Skip to content
Open
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
8 changes: 8 additions & 0 deletions cmd/labs/project/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ func (f *fetcher) loadRemoteProjectDefinition(cmd *cobra.Command, version string
var err error
if !offlineInstall {
raw, err = github.ReadFileFromRef(ctx, "databrickslabs", f.name, version, "labs.yml")
// Most repositories in the databrickslabs org don't ship a labs.yml manifest
// (e.g. libraries published to package indexes), so a missing file means the
// project isn't installable through the CLI, not that the download failed.
if errors.Is(err, github.ErrNotFound) {
return nil, fmt.Errorf("databrickslabs/%s@%s does not provide labs.yml (%w); "+

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch also catches a valid project requested at a version that does not exist, e.g. labs install blueprint@v9.9.9 (right after the "Installing unreleased version" warning). For that case the message is wrong: blueprint does provide labs.yml, the ref is just bad. Consider wording that covers both causes, e.g. labs.yml not found for databrickslabs/%s@%s; either this version does not exist or this project cannot be installed with the Databricks CLI, see ...

"this project cannot be installed with the Databricks CLI, "+
"see https://github.com/databrickslabs/%s for instructions", f.name, version, err, f.name)
}
if err != nil {
return nil, fmt.Errorf("read labs.yml from GitHub: %w", err)
}
Expand Down
30 changes: 30 additions & 0 deletions cmd/labs/project/fetcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package project_test

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/databricks/cli/cmd/labs/github"
"github.com/databricks/cli/internal/testcli"
"github.com/stretchr/testify/assert"
)

func TestInstallerFailsForProjectWithoutLabsYml(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/databrickslabs/blueprint/v0.3.15/labs.yml" {
w.WriteHeader(http.StatusNotFound)
return
}
t.Logf("Requested: %s", r.URL.Path)
t.FailNow()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, and it matches the existing pattern in installer_test.go, so fine to leave as is: t.FailNow() from the handler goroutine is documented as illegal (it must run on the test goroutine; here it only kills the handler via runtime.Goexit and the client sees a dropped connection). The idiomatic shape is t.Errorf(...) followed by http.Error(w, "unexpected request", http.StatusInternalServerError). Cleaning up all five occurrences in this file would make a nice separate PR.

}))
defer server.Close()
ctx := installerContext(t, server)

r := testcli.NewRunner(t, ctx, "labs", "install", "blueprint")
_, _, err := r.Run()
assert.ErrorIs(t, err, github.ErrNotFound)
assert.ErrorContains(t, err, "databrickslabs/blueprint@v0.3.15 does not provide labs.yml")
assert.ErrorContains(t, err, "cannot be installed with the Databricks CLI")
}
Loading