@@ -69,18 +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 ("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- 					log .Printf ("Parse error at %+v:\n %+v" , child .StartPoint (), child .Content (code ))
81- 					log .Printf ("The above was parsed as: %v" , child .String ())
82- 				}
83- 			}
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 ())
8495		}
8596	}
8697
0 commit comments