diff --git a/cmd/scip/lint.go b/cmd/scip/lint.go index 8c0a0ff0..05dee6cf 100644 --- a/cmd/scip/lint.go +++ b/cmd/scip/lint.go @@ -1,7 +1,7 @@ package main import ( - "errors" + stderrors "errors" "fmt" "sort" "strings" @@ -21,7 +21,7 @@ func lintCommand() cli.Command { Action: func(c *cli.Context) error { indexPath := c.Args().Get(0) if indexPath == "" { - return errors.New("missing argument for path to SCIP index") + return stderrors.New("missing argument for path to SCIP index") } return lintMain(indexPath) }, @@ -34,7 +34,7 @@ func lintMain(indexPath string) error { if err != nil { return err } - return errors.Join(lintMainPure(scipIndex).data...) + return stderrors.Join(lintMainPure(scipIndex).data...) } func lintMainPure(scipIndex *scip.Index) errorSet { diff --git a/cmd/scip/tests/reprolang/bindings/go/repro/ast.go b/cmd/scip/tests/reprolang/bindings/go/repro/ast.go index 372841fb..d77bb813 100644 --- a/cmd/scip/tests/reprolang/bindings/go/repro/ast.go +++ b/cmd/scip/tests/reprolang/bindings/go/repro/ast.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/cockroachdb/errors" sitter "github.com/smacker/go-tree-sitter" "github.com/sourcegraph/scip/bindings/go/scip" @@ -77,16 +78,17 @@ func NewRangePositionFromNode(node *sitter.Node) *scip.Range { } } -func (i *identifier) resolveSymbol(localScope *reproScope, context *reproContext) { +func (i *identifier) resolveSymbol(localScope *reproScope, context *reproContext) error { scope := context.globalScope if i.isLocalSymbol() { scope = localScope } symbol, ok := scope.names[i.value] if !ok { - symbol = "local ERROR_UNRESOLVED_SYMBOL" + return errors.Newf("could not resolve local symbol %q", i.value) } i.symbol = symbol + return nil } func (i *identifier) isLocalSymbol() bool { diff --git a/cmd/scip/tests/reprolang/bindings/go/repro/indexer.go b/cmd/scip/tests/reprolang/bindings/go/repro/indexer.go index 6fd8ea58..a48e79c1 100644 --- a/cmd/scip/tests/reprolang/bindings/go/repro/indexer.go +++ b/cmd/scip/tests/reprolang/bindings/go/repro/indexer.go @@ -2,7 +2,9 @@ package repro import ( "context" + stderrors "errors" + "github.com/cockroachdb/errors" "github.com/sourcegraph/scip/bindings/go/scip" ) @@ -69,8 +71,14 @@ func Index( } // Phase 3: resolve names for references + var allErrs error for _, file := range reproSources { - file.resolveReferences(ctx) + if err := file.resolveReferences(ctx); err != nil { + allErrs = stderrors.Join(allErrs, errors.Wrapf(err, "file %q", file.Source.AbsolutePath)) + } + } + if allErrs != nil { + return nil, allErrs } // Phase 4: emit SCIP diff --git a/cmd/scip/tests/reprolang/bindings/go/repro/namer.go b/cmd/scip/tests/reprolang/bindings/go/repro/namer.go index 6173ca8d..26049757 100644 --- a/cmd/scip/tests/reprolang/bindings/go/repro/namer.go +++ b/cmd/scip/tests/reprolang/bindings/go/repro/namer.go @@ -1,6 +1,7 @@ package repro import ( + stderrors "errors" "fmt" "github.com/sourcegraph/scip/bindings/go/scip" @@ -58,13 +59,14 @@ func (s *reproSourceFile) enterDefinitions(context *reproContext) { } // resolveReferences updates the .symbol field for all names of reference identifiers. -func (s *reproSourceFile) resolveReferences(context *reproContext) { +func (s *reproSourceFile) resolveReferences(context *reproContext) error { + var err error resolveIdents := func(rel relationships) { for _, ident := range rel.identifiers() { if ident == nil { continue } - ident.resolveSymbol(s.localScope, context) + err = stderrors.Join(err, ident.resolveSymbol(s.localScope, context)) } } for _, def := range s.definitions { @@ -74,8 +76,9 @@ func (s *reproSourceFile) resolveReferences(context *reproContext) { resolveIdents(rel.relations) } for _, ref := range s.references { - ref.name.resolveSymbol(s.localScope, context) + err = stderrors.Join(err, ref.name.resolveSymbol(s.localScope, context)) } + return err } // newGlobalSymbol returns an SCIP symbol for the given definition.