Skip to content

Commit

Permalink
improved error messages parsing (#2782)
Browse files Browse the repository at this point in the history
* improved regexp to also parse error messages with single quotes around header file name

* make regexp more specific, add test

* remove GH test failing escaped quotation marks

* fix formatting

* Use a more strict regexp / fix unit-test

---------

Co-authored-by: Cristian Maglie <c.maglie@arduino.cc>
  • Loading branch information
dennisppaul and cmaglie authored Jan 7, 2025
1 parent 6d9c930 commit 63bfd5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/arduino/builder/internal/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
return nil
}

// includeRegexp fixdoc
var includeRegexp = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
var includeRegexp = regexp.MustCompile(`(?ms)^\s*[0-9 |]*\s*#[ \t]*include\s*[<"](\S+)[">]`)

// IncludesFinderWithRegExp fixdoc
func IncludesFinderWithRegExp(source string) string {
Expand Down
10 changes: 10 additions & 0 deletions internal/arduino/builder/internal/detector/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ func TestIncludesFinderWithRegExpPaddedIncludes4(t *testing.T) {

require.Equal(t, "register.h", include)
}

func TestIncludesFinderWithRegExpPaddedIncludes5(t *testing.T) {
output := "/some/path/sketch.ino:23:42: fatal error: 'Foobar.h' file not found\n" +
" 23 | #include \"Foobar.h\"\n" +
" | ^~~~~~~~~~\n"

include := detector.IncludesFinderWithRegExp(output)

require.Equal(t, "Foobar.h", include)
}

0 comments on commit 63bfd5c

Please sign in to comment.