From 8edbbe93bde09834c8412ae17467fae3da0fb28e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 7 Jan 2020 16:56:03 +0100 Subject: [PATCH] Libraries dependencies: output error if no valid solution found Fix #534 --- commands/lib/resolve_deps.go | 14 ++++++++++++++ test/test_lib.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/commands/lib/resolve_deps.go b/commands/lib/resolve_deps.go index 1f2fa3f0340..166be751c25 100644 --- a/commands/lib/resolve_deps.go +++ b/commands/lib/resolve_deps.go @@ -42,6 +42,20 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe // Resolve all dependencies... deps := lm.Index.ResolveDependencies(reqLibRelease) + + // If no solution has been found + if len(deps) == 0 { + // Check if there is a problem with the first level deps + for _, directDep := range reqLibRelease.GetDependencies() { + if _, ok := lm.Index.Libraries[directDep.GetName()]; !ok { + return nil, fmt.Errorf("dependency '%s' is not available", directDep.GetName()) + } + } + + // Otherwise there is no possible solution, the depends field has an invalid formula + return nil, fmt.Errorf("no valid solution found") + } + res := []*rpc.LibraryDependencyStatus{} for _, dep := range deps { // ...and add information on currently installed versions of the libraries diff --git a/test/test_lib.py b/test/test_lib.py index 0155772ced6..39d4b15571e 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -60,6 +60,13 @@ def test_install(run_command): assert run_command("lib install {}".format(" ".join(libs))) assert run_command("lib install {}".format(" ".join(libs))) + # Test failing-install of library with wrong dependency + # (https://github.com/arduino/arduino-cli/issues/534) + result = run_command("lib install MD_Parola@3.2.0") + assert ( + "Error resolving dependencies for MD_Parola@3.2.0: dependency 'MD_MAX72xx' is not available" + in result.stderr + ) def test_update_index(run_command): result = run_command("lib update-index")