Skip to content

fix: library loading errors genereates unneeded compile failures #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
}
}

for _, err := range lm.RescanLibraries() {
s := status.Newf(codes.FailedPrecondition, tr("Loading libraries: %v"), err)
responseError(s)
for _, status := range lm.RescanLibraries() {
logrus.WithError(status.Err()).Warnf("Error loading library")
// TODO: report as warning: responseError(err)
}

// Refreshes the locale used, this will change the
Expand Down
26 changes: 26 additions & 0 deletions internal/integrationtest/compile_3/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package compile_test

import (
"fmt"
"testing"

"github.com/arduino/arduino-cli/internal/integrationtest"
Expand Down Expand Up @@ -154,3 +155,28 @@ func TestCompileRelativeLibraryPath(t *testing.T) {
require.Contains(t, string(stdout), "Used: "+FooLib.String())
require.Contains(t, string(stdout), "Not used: "+cli.SketchbookDir().Join("libraries", "FooLib").String())
}

func TestCompileWithInvalidLibrary(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)

// Make an empty library
emptyLibPath := cli.SketchbookDir().Join("libraries", "EmptyLib")
require.NoError(t, emptyLibPath.MkdirAll())

// prepare sketch
sketch, err := paths.New("testdata", "bare_minimum").Abs()
require.NoError(t, err)

// Compile must succeed
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", sketch.String())
require.NoError(t, err)

// Verbose compile must report invalid library
_, stderr, err := cli.Run("compile", "-v", "-b", "arduino:avr:uno", sketch.String())
require.NoError(t, err)
require.Contains(t, string(stderr), fmt.Sprintf("loading library from %s: invalid library: no header files found", emptyLibPath))
}
6 changes: 4 additions & 2 deletions legacy/builder/libraries_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
lm.AddLibrariesDir(folder, libraries.User)
}

if errs := lm.RescanLibraries(); len(errs) > 0 {
for _, status := range lm.RescanLibraries() {
// With the refactoring of the initialization step of the CLI we changed how
// errors are returned when loading platforms and libraries, that meant returning a list of
// errors instead of a single one to enhance the experience for the user.
// I have no intention right now to start a refactoring of the legacy package too, so
// here's this shitty solution for now.
// When we're gonna refactor the legacy package this will be gone.
return errors.WithStack(errs[0].Err())
if ctx.Verbose {
ctx.Warn(status.Message())
}
}

for _, dir := range ctx.LibraryDirs {
Expand Down