-
Notifications
You must be signed in to change notification settings - Fork 0
Adds safety checks when accessing database env #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ export async function getPendingEvents( | |
| ): Promise<WorkflowEvent[]> { | ||
| const now = Date.now(); | ||
| const result = | ||
| await env.MESH_REQUEST_CONTEXT.state.DATABASE.DATABASES_RUN_SQL({ | ||
| await env.MESH_REQUEST_CONTEXT?.state?.DATABASE.DATABASES_RUN_SQL({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Incomplete optional chaining will crash if Prompt for AI agents |
||
| sql: `SELECT * FROM workflow_event WHERE execution_id = ? AND consumed_at IS NULL | ||
| AND (visible_at IS NULL OR visible_at <= ?) ${type ? "AND type = ?" : ""} | ||
| ORDER BY visible_at ASC NULLS FIRST, created_at ASC`, | ||
|
|
@@ -48,7 +48,7 @@ export async function consumeSignal( | |
| signalId: string, | ||
| ): Promise<boolean> { | ||
| const result = | ||
| await env.MESH_REQUEST_CONTEXT.state.DATABASE.DATABASES_RUN_SQL({ | ||
| await env.MESH_REQUEST_CONTEXT?.state?.DATABASE.DATABASES_RUN_SQL({ | ||
| sql: `UPDATE workflow_event SET consumed_at = ? WHERE id = ? AND consumed_at IS NULL RETURNING id`, | ||
| params: [Date.now(), signalId], | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,14 +114,14 @@ export const createListTool = (env: Env) => | |
| `; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Incomplete optional chaining creates a false sense of safety. If Prompt for AI agents |
||
|
|
||
| const itemsResult: any = | ||
| await env.MESH_REQUEST_CONTEXT.state.DATABASE.DATABASES_RUN_SQL({ | ||
| await env.MESH_REQUEST_CONTEXT?.state?.DATABASE.DATABASES_RUN_SQL({ | ||
| sql, | ||
| params: [...params, limit, offset], | ||
| }); | ||
|
|
||
| const countQuery = `SELECT COUNT(*) as count FROM workflow_collection ${whereClause}`; | ||
| const countResult = | ||
| await env.MESH_REQUEST_CONTEXT.state.DATABASE.DATABASES_RUN_SQL({ | ||
| await env.MESH_REQUEST_CONTEXT?.state?.DATABASE.DATABASES_RUN_SQL({ | ||
| sql: countQuery, | ||
| params, | ||
| }); | ||
|
|
@@ -147,7 +147,7 @@ export async function getWorkflowCollection( | |
| id: string, | ||
| ): Promise<Workflow | null> { | ||
| const result = | ||
| await env.MESH_REQUEST_CONTEXT.state.DATABASE.DATABASES_RUN_SQL({ | ||
| await env.MESH_REQUEST_CONTEXT?.state?.DATABASE.DATABASES_RUN_SQL({ | ||
| sql: "SELECT * FROM workflow_collection WHERE id = ? LIMIT 1", | ||
| params: [id], | ||
| }); | ||
|
|
@@ -313,7 +313,7 @@ y UPDATE workflow_collection | |
| `; | ||
|
|
||
| const result = | ||
| await env.MESH_REQUEST_CONTEXT.state.DATABASE.DATABASES_RUN_SQL({ | ||
| await env.MESH_REQUEST_CONTEXT?.state?.DATABASE.DATABASES_RUN_SQL({ | ||
| sql, | ||
| params, | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Incomplete optional chaining will still throw TypeError. If
MESH_REQUEST_CONTEXTorstateis nullish,?.DATABASEevaluates toundefined, and calling.DATABASES_RUN_SQL()onundefinedthrows. Consider adding?.beforeDATABASES_RUN_SQLand handling the undefined response, or throwing an explicit error early if the context is required.Prompt for AI agents