Skip to content

Commit c6c6068

Browse files
Fix exists() type safety and error handling
Address code review feedback on PR #152: - Fix TypeScript compilation by importing FileExistsRequest from @repo/shared - Add sessionId parameter to ISandbox.exists() for API consistency - Fix error handling to propagate execution failures properly Co-authored-by: Naresh <[email protected]>
1 parent 70d6a98 commit c6c6068

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/sandbox-container/src/handlers/file-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
DeleteFileResult,
3+
FileExistsRequest,
34
FileExistsResult,
45
FileStreamEvent,
56
ListFilesResult,Logger,
@@ -13,7 +14,6 @@ import { ErrorCode } from '@repo/shared/errors';
1314

1415
import type {
1516
DeleteFileRequest,
16-
FileExistsRequest,
1717
ListFilesRequest,
1818
MkdirRequest,
1919
MoveFileRequest,

packages/sandbox-container/src/services/file-service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,17 @@ export class FileService implements FileSystemOperations {
721721
const execResult = await this.sessionManager.executeInSession(sessionId, command);
722722

723723
if (!execResult.success) {
724-
// If execution fails, treat as non-existent
724+
// If command execution fails, propagate the error
725725
return {
726-
success: true,
727-
data: false
726+
success: false,
727+
error: {
728+
message: `Failed to check file existence for '${path}': Command execution failed`,
729+
code: ErrorCode.FILESYSTEM_ERROR,
730+
details: {
731+
path,
732+
operation: Operation.FILE_STAT
733+
} satisfies FileSystemContext
734+
}
728735
};
729736
}
730737

packages/shared/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ export interface ISandbox {
655655
renameFile(oldPath: string, newPath: string): Promise<RenameFileResult>;
656656
moveFile(sourcePath: string, destinationPath: string): Promise<MoveFileResult>;
657657
listFiles(path: string, options?: ListFilesOptions): Promise<ListFilesResult>;
658-
exists(path: string): Promise<FileExistsResult>;
658+
exists(path: string, sessionId?: string): Promise<FileExistsResult>;
659659

660660
// Git operations
661661
gitCheckout(repoUrl: string, options?: { branch?: string; targetDir?: string }): Promise<GitCheckoutResult>;

0 commit comments

Comments
 (0)