Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(ws,sidebar): structured error payload and prevent horizontal overflow on project import #1045

Closedjomlamladen(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/1045/headopened View on GitHub

Showing 3 changed files with 65 additions and 11 deletions.

x
0 of 3 viewed, 3 left
45 additions and 3 deletionsapps/server/src/wsServer.tsModified
View file
@@ -20,7 +20,9 @@
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
ProjectId,
ThreadId,
+ type WsError,
WS_CHANNELS,
+ WS_ERROR_CODES,
WS_METHODS,
WebSocketRequest,
type WsResponse as WsResponseMessage,
@@ -231,6 +233,40 @@
message: Schema.String,
}) {}
​
+function buildWsErrorForClient(cause: Cause.Cause<unknown>): WsError {
+ const defect = Cause.squash(cause);
+ const rawMessage = defect instanceof Error ? defect.message : Cause.pretty(cause);
+ const firstLine = rawMessage.split("\n")[0]?.trim() ?? rawMessage;
+ const message = firstLine.replace(/^Error:\s*/i, "");
+​
+ const dirNotExistPrefix = "Project directory does not exist: ";
+ const pathNotDirPrefix = "Project path is not a directory: ";
+ if (message.startsWith(dirNotExistPrefix)) {
+ return {
+ code: WS_ERROR_CODES.projectDirNotExist,
+ message: "Project directory does not exist",
+ path: message.slice(dirNotExistPrefix.length).trim() || undefined,
+ };
+ }