mirror of
https://github.com/esengine/DeepSeek-Reasonix.git
synced 2026-11-07 02:36:01 -10:00
fix(serve): opening a project whose folder is gone is refused with workspace.folder_missing and the path, not the system's stat sentence
This commit is contained in:
1 parent
ec45959a6e
commit
1ff0525a34
2 files changed
+18
-1
No files matched your search
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user