@@ -69,23 +69,29 @@ func ParseCode(code []byte, path string) (*sitter.Node, error) {
6969 }
7070
7171 root := tree .RootNode ()
72- if root .HasError () {
73- log .Printf ("WARNING: failed to parse %q. The resulting BUILD target may be incorrect." , path )
74-
75- verbose , envExists := os .LookupEnv ("RULES_PYTHON_GAZELLE_VERBOSE" )
76- if envExists && verbose == "1" {
77- for i := 0 ; i < int (root .ChildCount ()); i ++ {
78- child := root .Child (i )
79- if child .IsError () {
80- // Example logs:
81- // gazelle: Parse error at {Row:1 Column:0}:
82- // def search_one_more_level[T]():
83- log .Printf ("Parse error at %+v:\n %+v" , child .StartPoint (), child .Content (code ))
84- // Log the internal tree-sitter representation of what was parsed. Eg:
85- // gazelle: The above was parsed as: (ERROR (identifier) (call function: (list (identifier)) arguments: (argument_list)))
86- log .Printf ("The above was parsed as: %v" , child .String ())
87- }
88- }
72+ if ! root .HasError () {
73+ return root , nil
74+ }
75+
76+ log .Printf ("WARNING: failed to parse %q. The resulting BUILD target may be incorrect." , path )
77+
78+ // Note: we intentionally do not return an error even when root.HasError because the parse
79+ // failure may be in some part of the code that Gazelle doesn't care about.
80+ verbose , envExists := os .LookupEnv ("RULES_PYTHON_GAZELLE_VERBOSE" )
81+ if ! envExists || verbose != "1" {
82+ return root , nil
83+ }
84+
85+ for i := 0 ; i < int (root .ChildCount ()); i ++ {
86+ child := root .Child (i )
87+ if child .IsError () {
88+ // Example logs:
89+ // gazelle: Parse error at {Row:1 Column:0}:
90+ // def search_one_more_level[T]():
91+ log .Printf ("Parse error at %+v:\n %+v" , child .StartPoint (), child .Content (code ))
92+ // Log the internal tree-sitter representation of what was parsed. Eg:
93+ // gazelle: The above was parsed as: (ERROR (identifier) (call function: (list (identifier)) arguments: (argument_list)))
94+ log .Printf ("The above was parsed as: %v" , child .String ())
8995 }
9096 }
9197
0 commit comments