Improve error message when path is not a bundle template (#985)

Adds better error message when input path is not a bundle template

before:
```
shreyas.goenka@THW32HFW6T bricks % cli bundle init ~/bricks
Error: open /Users/shreyas.goenka/bricks/databricks_template_schema.json: no such file or directory
```

after:
```
shreyas.goenka@THW32HFW6T bricks % cli bundle init ~/bricks
Error: expected to find a template schema file at /Users/shreyas.goenka/bricks/databricks_template_schema.json
```
This commit is contained in:
shreyas-goenka 2023-11-22 13:25:16 +01:00 committed by GitHub
parent 48e293c72c
commit d9fe2ab43d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package template
import (
"context"
"embed"
"fmt"
"io/fs"
"os"
"path"
@ -43,6 +44,10 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st
schemaPath := filepath.Join(templateRoot, schemaFileName)
helpers := loadHelpers(ctx)
if _, err := os.Stat(schemaPath); os.IsNotExist(err) {
return fmt.Errorf("not a bundle template: expected to find a template schema file at %s", schemaPath)
}
config, err := newConfig(ctx, schemaPath)
if err != nil {
return err

View File

@ -0,0 +1,24 @@
package template
import (
"context"
"fmt"
"path/filepath"
"testing"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/databricks-sdk-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMaterializeForNonTemplateDirectory(t *testing.T) {
tmpDir := t.TempDir()
w, err := databricks.NewWorkspaceClient(&databricks.Config{})
require.NoError(t, err)
ctx := root.SetWorkspaceClient(context.Background(), w)
// Try to materialize a non-template directory.
err = Materialize(ctx, "", tmpDir, "")
assert.EqualError(t, err, fmt.Sprintf("not a bundle template: expected to find a template schema file at %s", filepath.Join(tmpDir, schemaFileName)))
}