From 5b77be186e34aad919b67e4093c7a4d9882a193c Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 20 Nov 2024 17:57:56 +0100 Subject: [PATCH] Extend notebook not found error to warn about missing file extesion --- bundle/config/mutator/translate_paths.go | 12 +++++++ bundle/config/mutator/translate_paths_test.go | 32 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/bundle/config/mutator/translate_paths.go b/bundle/config/mutator/translate_paths.go index 1e2484c7..58c088b8 100644 --- a/bundle/config/mutator/translate_paths.go +++ b/bundle/config/mutator/translate_paths.go @@ -126,6 +126,18 @@ func (t *translateContext) rewritePath( func (t *translateContext) translateNotebookPath(literal, localFullPath, localRelPath, remotePath string) (string, error) { nb, _, err := notebook.DetectWithFS(t.b.SyncRoot, filepath.ToSlash(localRelPath)) if errors.Is(err, fs.ErrNotExist) { + if filepath.Ext(localFullPath) == notebook.ExtensionNone { + return "", fmt.Errorf(`notebook %s not found. Local notebook references are expected +to contain one of the following file extensions: [%s]`, + literal, + strings.Join([]string{ + notebook.ExtensionPython, + notebook.ExtensionR, + notebook.ExtensionScala, + notebook.ExtensionSql, + notebook.ExtensionJupyter}, ", ")) + } + return "", fmt.Errorf("notebook %s not found", literal) } if err != nil { diff --git a/bundle/config/mutator/translate_paths_test.go b/bundle/config/mutator/translate_paths_test.go index a2032f81..ab54de81 100644 --- a/bundle/config/mutator/translate_paths_test.go +++ b/bundle/config/mutator/translate_paths_test.go @@ -508,6 +508,38 @@ func TestPipelineNotebookDoesNotExistError(t *testing.T) { assert.EqualError(t, diags.Error(), "notebook ./doesnt_exist.py not found") } +func TestPipelineNotebookDoesNotExistErrorWithoutExtension(t *testing.T) { + dir := t.TempDir() + + b := &bundle.Bundle{ + SyncRootPath: dir, + SyncRoot: vfs.MustNew(dir), + Config: config.Root{ + Resources: config.Resources{ + Pipelines: map[string]*resources.Pipeline{ + "pipeline": { + PipelineSpec: &pipelines.PipelineSpec{ + Libraries: []pipelines.PipelineLibrary{ + { + Notebook: &pipelines.NotebookLibrary{ + Path: "./doesnt_exist", + }, + }, + }, + }, + }, + }, + }, + }, + } + + bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "fake.yml")}}) + + diags := bundle.Apply(context.Background(), b, mutator.TranslatePaths()) + assert.EqualError(t, diags.Error(), `notebook ./doesnt_exist not found. Local notebook references are expected +to contain one of the following file extensions: [.py, .r, .scala, .sql, .ipynb]`) +} + func TestPipelineFileDoesNotExistError(t *testing.T) { dir := t.TempDir()