Skip to content

Commit 8dd53f1

Browse files
committed
Parse the execute response instead of assuming it's valid
1 parent ac0aeb9 commit 8dd53f1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

ui/frontend/reducers/output/execute.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ export interface ExecuteRequestBody {
6767
backtrace: boolean;
6868
}
6969

70-
interface ExecuteResponseBody {
71-
success: boolean;
72-
exitDetail: string;
73-
stdout: string;
74-
stderr: string;
75-
}
70+
const ExecuteResponseBody = z.object({
71+
success: z.boolean(),
72+
exitDetail: z.string(),
73+
stdout: z.string(),
74+
stderr: z.string(),
75+
});
76+
type ExecuteResponseBody = z.infer<typeof ExecuteResponseBody>;
7677

77-
export const performExecute = createAsyncThunk(sliceName, async (payload: ExecuteRequestBody) =>
78-
adaptFetchError(() => jsonPost<ExecuteResponseBody>(routes.execute, payload)),
79-
);
78+
export const performExecute = createAsyncThunk(sliceName, async (payload: ExecuteRequestBody) => {
79+
const d = await adaptFetchError(() => jsonPost(routes.execute, payload));
80+
return ExecuteResponseBody.parseAsync(d);
81+
});
8082

8183
const prepareWithCurrentSequenceNumber = <P>(payload: P, sequenceNumber: number) => ({
8284
payload,

0 commit comments

Comments
 (0)