Do not convert nil to 404

This commit is contained in:
Denis Bilenko 2025-02-12 12:48:44 +01:00
parent 7709407df5
commit c9beddc97a
5 changed files with 32 additions and 13 deletions

View File

@ -9,7 +9,7 @@
10:07:59 Debug: ApplyReadOnly pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:folder_permissions
10:07:59 Debug: ApplyReadOnly pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:validate_sync_patterns
10:07:59 Debug: Path /Workspace/Users/[USERNAME]/.bundle/debug/default/files has type directory (ID: 0) pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync
10:07:59 Debug: non-retriable error: Not Found pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
< HTTP/0.0 000 Not Found (Error: Not Found) pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
10:07:59 Debug: non-retriable error: Workspace path not found pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
< HTTP/0.0 000 OK pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
< } pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
< } pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true

View File

@ -78,6 +78,9 @@
10:07:59 Debug: No script defined for postinit, skipping pid=12345 mutator=initialize mutator=seq mutator=scripts.postinit
10:07:59 Debug: Apply pid=12345 mutator=validate
10:07:59 Debug: GET /api/2.0/workspace/get-status?path=/Workspace/Users/[USERNAME]/.bundle/debug/default/files
< HTTP/1.1 404 Not Found
< {
< "message": "Workspace path not found"
10:07:59 Debug: POST /api/2.0/workspace/mkdirs
> {
> "path": "/Workspace/Users/[USERNAME]/.bundle/debug/default/files"

View File

@ -16,6 +16,6 @@ custom
response
>>> errcode [CLI] workspace get-status /a/b/c
Error: Not Found
Error: Workspace path not found
Exit code: 1

View File

@ -32,20 +32,27 @@ func NewFakeWorkspace() *FakeWorkspace {
}
}
func (s *FakeWorkspace) WorkspaceGetStatus(path string) *workspace.ObjectInfo {
func (s *FakeWorkspace) WorkspaceGetStatus(path string) Response {
if s.directories[path] {
return &workspace.ObjectInfo{
ObjectType: "DIRECTORY",
Path: path,
return Response{
Body: &workspace.ObjectInfo{
ObjectType: "DIRECTORY",
Path: path,
},
}
} else if _, ok := s.files[path]; ok {
return &workspace.ObjectInfo{
ObjectType: "FILE",
Path: path,
Language: "SCALA",
return Response{
Body: &workspace.ObjectInfo{
ObjectType: "FILE",
Path: path,
Language: "SCALA",
},
}
} else {
return nil
return Response{
StatusCode: 404,
Body: map[string]string{"message": "Workspace path not found"},
}
}
}

View File

@ -87,7 +87,8 @@ func normalizeResponse(t testutil.TestingT, resp any) encodedResponse {
func normalizeResponseBody(t testutil.TestingT, resp any) encodedResponse {
if isNil(resp) {
return encodedResponse{StatusCode: 404, Body: []byte{}}
t.Errorf("Handler must not return nil")
return encodedResponse{StatusCode: 500}
}
respBytes, ok := resp.([]byte)
@ -108,6 +109,14 @@ func normalizeResponseBody(t testutil.TestingT, resp any) encodedResponse {
respStruct, ok := resp.(Response)
if ok {
if isNil(respStruct.Body) {
return encodedResponse{
StatusCode: respStruct.StatusCode,
Headers: respStruct.Headers,
Body: []byte{},
}
}
bytesVal, isBytes := respStruct.Body.([]byte)
if isBytes {
return encodedResponse{