Unverified Commit 9a08fec5 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

fix: library loading errors genereates unneeded compile failures (#2139)

parent fe91ec6e
...@@ -458,9 +458,9 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro ...@@ -458,9 +458,9 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
} }
} }
for _, err := range lm.RescanLibraries() { for _, status := range lm.RescanLibraries() {
s := status.Newf(codes.FailedPrecondition, tr("Loading libraries: %v"), err) logrus.WithError(status.Err()).Warnf("Error loading library")
responseError(s) // TODO: report as warning: responseError(err)
} }
// Refreshes the locale used, this will change the // Refreshes the locale used, this will change the
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package compile_test package compile_test
import ( import (
"fmt"
"testing" "testing"
"github.com/arduino/arduino-cli/internal/integrationtest" "github.com/arduino/arduino-cli/internal/integrationtest"
...@@ -154,3 +155,28 @@ func TestCompileRelativeLibraryPath(t *testing.T) { ...@@ -154,3 +155,28 @@ func TestCompileRelativeLibraryPath(t *testing.T) {
require.Contains(t, string(stdout), "Used: "+FooLib.String()) require.Contains(t, string(stdout), "Used: "+FooLib.String())
require.Contains(t, string(stdout), "Not used: "+cli.SketchbookDir().Join("libraries", "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))
}
...@@ -56,14 +56,16 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error { ...@@ -56,14 +56,16 @@ func (s *LibrariesLoader) Run(ctx *types.Context) error {
lm.AddLibrariesDir(folder, libraries.User) 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 // 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 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. // 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 // I have no intention right now to start a refactoring of the legacy package too, so
// here's this shitty solution for now. // here's this shitty solution for now.
// When we're gonna refactor the legacy package this will be gone. // 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 { for _, dir := range ctx.LibraryDirs {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment