diff --git a/internal/frontend/serve/terminals_test.go b/internal/frontend/serve/terminals_test.go index 16b61cf3e2..a6f5cc4f5b 100644 --- a/internal/frontend/serve/terminals_test.go +++ b/internal/frontend/serve/terminals_test.go @@ -4,8 +4,10 @@ import ( "bufio" "encoding/base64" "encoding/json" + "errors" "net/http" "net/http/httptest" + "path/filepath" "reasonix/internal/base/testenv" "runtime" "strings" @@ -188,3 +190,14 @@ func TestARemotePanesTerminalsAreForwardedForTheHostAndNeverForADevice(t *testin t.Fatalf("the host's request was forwarded %d times, want once", len(rk.cookies)) } } + +func TestAMissingProjectFolderIsRefusedByCodeNotByTheSystemsSentence(t *testing.T) { + _, err := resolveWorkspaceDir(filepath.Join(t.TempDir(), "gone", "worktree")) + var c *coded + if !errors.As(err, &c) || c.reason.Code != codeWorkspaceMissing || c.status != http.StatusBadRequest { + t.Fatalf("a folder that is not there = %v, want a %s refusal with 400", err, codeWorkspaceMissing) + } + if c.reason.Params["path"] == "" { + t.Fatal("the refusal must carry the path so the page can say which folder") + } +} diff --git a/internal/frontend/serve/workspace.go b/internal/frontend/serve/workspace.go index 3c14574fb7..105271875a 100644 --- a/internal/frontend/serve/workspace.go +++ b/internal/frontend/serve/workspace.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "io/fs" "log/slog" "net/http" "os" @@ -149,11 +150,14 @@ func resolveWorkspaceDir(dir string) (string, error) { return "", err } info, err := os.Stat(abs) + if errors.Is(err, fs.ErrNotExist) { + return "", refusal(http.StatusBadRequest, codeWorkspaceMissing, err, map[string]any{"path": abs}) + } if err != nil { return "", err } if !info.IsDir() { - return "", fmt.Errorf("%s is not a directory", abs) + return "", refusal(http.StatusBadRequest, codeWorkspaceMissing, fmt.Errorf("%s is not a directory", abs), map[string]any{"path": abs}) } return abs, nil }