From b93b0e62c9cf98a99ab84f62be3075b81a2ad3e1 Mon Sep 17 00:00:00 2001 From: Joshua Bronson Date: Mon, 25 May 2026 10:24:43 -0500 Subject: [PATCH] fix(gazelle): guard against nil proto config in loadConfig proto.GetProtoConfig() returns nil when the proto Gazelle language is not loaded alongside buf. Guard the return value to prevent a nil pointer dereference panic. Fixes #147 --- gazelle/buf/config.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gazelle/buf/config.go b/gazelle/buf/config.go index c1f45f4..884619b 100644 --- a/gazelle/buf/config.go +++ b/gazelle/buf/config.go @@ -113,17 +113,21 @@ func loadConfig(gazelleConfig *config.Config, packageRelativePath string, file * // Here we set the config if the directive is not present if config.ModuleRoot && packageRelativePath != "" { protoConfig := proto.GetProtoConfig(gazelleConfig) - stripImportPrefix := "/" + packageRelativePath - if protoConfig.StripImportPrefix == "" { - protoConfig.StripImportPrefix = stripImportPrefix - } - if protoConfig.StripImportPrefix != stripImportPrefix { - log.Printf( - "strip_import_prefix at %s should be %s but is %s", - packageRelativePath, - stripImportPrefix, - protoConfig.StripImportPrefix, - ) + if protoConfig == nil { + log.Print("buf: proto language is not enabled; skipping strip_import_prefix configuration") + } else { + stripImportPrefix := "/" + packageRelativePath + if protoConfig.StripImportPrefix == "" { + protoConfig.StripImportPrefix = stripImportPrefix + } + if protoConfig.StripImportPrefix != stripImportPrefix { + log.Printf( + "strip_import_prefix at %s should be %s but is %s", + packageRelativePath, + stripImportPrefix, + protoConfig.StripImportPrefix, + ) + } } } if file == nil {