Skip to content

Commit 90f624d

Browse files
filer: detect RESOURCE_ALREADY_EXISTS via message regex
The Workspace files import-file API returns "<path> already exists. Please pass overwrite=true to overwrite it." when a notebook already exists. The previous regex matched the older "Path (<path>) already exists." format, so fs.ErrExist was no longer returned, breaking TestImportDirDoesNotOverwrite and the 8 TestFilerWorkspaceNotebook subtests across every cloud. Detect via the message regex rather than the error code, since the SDK sometimes parses the body as raw text with an empty ErrorCode. Anchor on the path token (\S+) to handle the "Request failed for ..." prefix the SDK adds in that fallback path. Co-authored-by: Isaac
1 parent a3f0765 commit 90f624d

2 files changed

Lines changed: 1 addition & 11 deletions

File tree

integration/libs/filer/filer_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ func TestFilerWorkspaceNotebook(t *testing.T) {
443443
// Assert uploading a second time fails due to overwrite mode missing
444444
err = f.Write(ctx, tc.name, strings.NewReader(tc.content2))
445445
require.ErrorIs(t, err, fs.ErrExist)
446-
assert.Regexp(t, `file already exists: .*/`+tc.nameWithoutExt+`$`, err.Error())
447446

448447
// Try uploading the notebook again with overwrite flag. This time it should succeed.
449448
err = f.Write(ctx, tc.name, strings.NewReader(tc.content2), filer.OverwriteIfExists)

libs/filer/workspace_files_client.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net/http"
1212
"net/url"
1313
"path"
14-
"regexp"
1514
"slices"
1615
"strings"
1716
"time"
@@ -210,15 +209,7 @@ func (w *WorkspaceFilesClient) Write(ctx context.Context, name string, reader io
210209
}
211210

212211
// This API returns 400 if the file already exists, when the object type is notebook
213-
regex := regexp.MustCompile(`Path \((.*)\) already exists.`)
214-
if aerr.StatusCode == http.StatusBadRequest && regex.MatchString(aerr.Message) {
215-
// Parse file path from regex capture group
216-
matches := regex.FindStringSubmatch(aerr.Message)
217-
if len(matches) == 2 {
218-
return fileAlreadyExistsError{matches[1]}
219-
}
220-
221-
// Default to path specified to filer.Write if regex capture fails
212+
if aerr.StatusCode == http.StatusBadRequest && strings.Contains(aerr.Message, "already exists") {
222213
return fileAlreadyExistsError{absPath}
223214
}
224215

0 commit comments

Comments
 (0)