aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-11 09:24:53 +0000
committerFuwn <[email protected]>2026-04-11 09:24:53 +0000
commitb5b426f4b85d97d2fbbe92a1eb4388c5ecd28e7e (patch)
tree0716868a3774fd2b22aeef429bb608e9de958a1c
parentfix(analyze): improve uppercase token detection accuracy (diff)
downloadkivia-b5b426f4b85d97d2fbbe92a1eb4388c5ecd28e7e.tar.xz
kivia-b5b426f4b85d97d2fbbe92a1eb4388c5ecd28e7e.zip
fix(collect): handle nil range keys and aggregate parse errors
-rw-r--r--internal/collect/collect.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/internal/collect/collect.go b/internal/collect/collect.go
index ccb3b46..d7db9a0 100644
--- a/internal/collect/collect.go
+++ b/internal/collect/collect.go
@@ -40,11 +40,15 @@ func FromPath(path string) ([]Identifier, error) {
fileSet := token.NewFileSet()
identifiers := make([]Identifier, 0, 128)
+ var parseErrors []error
+
for _, filePath := range files {
fileNode, parseErr := parser.ParseFile(fileSet, filePath, nil, parser.SkipObjectResolution)
if parseErr != nil {
- return nil, fmt.Errorf("Failed to parse %s: %w", filePath, parseErr)
+ parseErrors = append(parseErrors, fmt.Errorf("Failed to parse %s: %w", filePath, parseErr))
+
+ continue
}
collector := visitor{
@@ -57,6 +61,10 @@ func FromPath(path string) ([]Identifier, error) {
identifiers = append(identifiers, collector.identifiers...)
}
+ if len(parseErrors) > 0 {
+ return nil, parseErrors[0]
+ }
+
return identifiers, nil
}
@@ -124,12 +132,16 @@ func (identifierVisitor *visitor) Visit(node ast.Node) ast.Visitor {
break
}
- if keyIdentifier, ok := typedNode.Key.(*ast.Ident); ok {
- identifierVisitor.addIdentifier(keyIdentifier, "rangeKey", Context{ValueExpression: renderExpression(identifierVisitor.fileSet, typedNode.X)})
+ if typedNode.Key != nil {
+ if keyIdentifier, ok := typedNode.Key.(*ast.Ident); ok {
+ identifierVisitor.addIdentifier(keyIdentifier, "rangeKey", Context{ValueExpression: renderExpression(identifierVisitor.fileSet, typedNode.X)})
+ }
}
- if valueIdentifier, ok := typedNode.Value.(*ast.Ident); ok {
- identifierVisitor.addIdentifier(valueIdentifier, "rangeValue", Context{ValueExpression: renderExpression(identifierVisitor.fileSet, typedNode.X)})
+ if typedNode.Value != nil {
+ if valueIdentifier, ok := typedNode.Value.(*ast.Ident); ok {
+ identifierVisitor.addIdentifier(valueIdentifier, "rangeValue", Context{ValueExpression: renderExpression(identifierVisitor.fileSet, typedNode.X)})
+ }
}
}
@@ -228,7 +240,7 @@ func discoverFiles(path string) ([]string, error) {
recursive := false
if strings.HasSuffix(path, "/...") {
- searchRoot = strings.TrimSuffix(path, "/...")
+ searchRoot, _ = strings.CutSuffix(path, "/...")
recursive = true
}
@@ -264,7 +276,7 @@ func discoverFiles(path string) ([]string, error) {
}
if !recursive && candidate != searchRoot {
- return filepath.SkipDir
+ return fs.SkipDir
}
return nil