Skip to content

Commit

Permalink
Handle per-step errors and returning error data (#411)
Browse files Browse the repository at this point in the history
## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

Adds handling and returning of per-step errors instead of the current
error flow of intentionlly throwing to trigger a `500 Internal Server
Error`.

## Checklist
<!-- Tick these items off as you progress. -->
<!-- If an item isn't applicable, ideally please strikeout the item by
wrapping it in "~~"" and suffix it with "N/A My reason for skipping
this." -->
<!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" -->

- [x] Added a [docs PR](https://github.com/inngest/website) that
references this PR
- [x] Added unit/integration tests
- [x] Added changesets if applicable
- [x] inngest/inngest#843 must be shipped and upstreamed to Cloud before
we merge
- [x] Ensure error serialization always creates a `StepError` for step
errors

## Related

- Relies on inngest/inngest#1058
- inngest/website#655
  • Loading branch information
jpwilliams authored Jan 25, 2024
1 parent 2f01a27 commit 3b35c1c
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-seahorses-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": minor
---

Add handling of per-step errors and returning step names during error cases to better display issues in the UI
15 changes: 11 additions & 4 deletions packages/inngest/etc/inngest.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/inngest/scripts/integrationTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ async function startDevServer(
devServerPort.toString(),
"--no-discovery",
"--no-poll",
"--retry-interval",
"1",
"--log-level",
"trace",
"--sdk-url",
`http://localhost:${exampleServerPort}/api/inngest`,
],
Expand Down
21 changes: 12 additions & 9 deletions packages/inngest/src/components/InngestCommHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,7 @@ export class InngestCommHandler<
* `null`, as this is appropriately serializable by JSON.
*/
const opDataUndefinedToNull = (op: OutgoingOp) => {
const opData = z.object({ data: z.any() }).safeParse(op.data);

if (opData.success) {
(op.data as { data: unknown }).data = undefinedToNull(
opData.data.data
);
}

op.data = undefinedToNull(op.data);
return op;
};

Expand Down Expand Up @@ -791,7 +784,17 @@ export class InngestCommHandler<

return {
status: 206,
headers: { "Content-Type": "application/json" },
headers: {
"Content-Type": "application/json",
...(typeof result.retriable !== "undefined"
? {
[headerKeys.NoRetry]: result.retriable ? "false" : "true",
...(typeof result.retriable === "string"
? { [headerKeys.RetryAfter]: result.retriable }
: {}),
}
: {}),
},
body: stringify([step]),
version,
};
Expand Down
Loading

0 comments on commit 3b35c1c

Please sign in to comment.