From a2de5f8db4aa324e52f696e6b822d9852d8c5782 Mon Sep 17 00:00:00 2001 From: Andreas Jansson Date: Mon, 8 Mar 2021 21:20:29 -0500 Subject: [PATCH] throw error if checkpointing missing file Signed-off-by: Andreas Jansson --- go/pkg/repository/repository.go | 7 +++++++ go/pkg/repository/repository_test.go | 4 ++++ python/tests/test_experiment.py | 3 +++ 3 files changed, 14 insertions(+) diff --git a/go/pkg/repository/repository.go b/go/pkg/repository/repository.go index 3994d544..93ef9348 100644 --- a/go/pkg/repository/repository.go +++ b/go/pkg/repository/repository.go @@ -396,6 +396,9 @@ func CopyToTempDir(localPath string, includePath string) (tempDir string, err er // then copy the ones that match the includePath. // TODO(andreas): only scan files in the includePath filesToCopy, err := getListOfFilesToPut(localPath, tempDir) + if err != nil { + return "", err + } count := 0 for _, file := range filesToCopy { @@ -424,6 +427,10 @@ func CopyToTempDir(localPath string, includePath string) (tempDir string, err er count += 1 } + if count == 0 { + return "", fmt.Errorf("No files matched '%s' in %s", includePath, localPath) + } + console.Debug("Copied %d files to temporary directory (took %.3f seconds)", count, time.Since(start).Seconds()) return tempDir, err diff --git a/go/pkg/repository/repository_test.go b/go/pkg/repository/repository_test.go index 128fff77..2da12cb5 100644 --- a/go/pkg/repository/repository_test.go +++ b/go/pkg/repository/repository_test.go @@ -202,4 +202,8 @@ func TestCopyToTempDir(t *testing.T) { contents, err = ioutil.ReadFile(path.Join(tempDir, "my/folder/bar")) require.NoError(t, err) require.Equal(t, "bar", string(contents)) + + // with missing file + _, err = CopyToTempDir(dir, "not-existing") + require.Error(t, err) } diff --git a/python/tests/test_experiment.py b/python/tests/test_experiment.py index 8ce63734..d7363621 100644 --- a/python/tests/test_experiment.py +++ b/python/tests/test_experiment.py @@ -530,6 +530,9 @@ def test_create_project_options( with open("keepsake.yaml", "w") as f: f.write("repository: file://.keepsake/") + with open("foo.txt", "w") as f: + f.write("hello world") + project = Project(repository=repo, directory=directory) if exception: