Skip to content

Commit

Permalink
Make data.error parsing for inngest/function.failed more resilient (
Browse files Browse the repository at this point in the history
#476)

## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

Complements inngest/inngest#1077 by also making SDK error parsing more
resilient, allowing replay of these events with an updated SDK.

## 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" -->

- [ ] ~~Added a [docs PR](https://github.com/inngest/website) that
references this PR~~ N/A
- [ ] Added unit/integration tests
- [x] Added changesets if applicable

## Related
<!-- A space for any related links, issues, or PRs. -->
<!-- Linear issues are autolinked. -->
<!-- e.g. - INN-123 -->
<!-- GitHub issues/PRs can be linked using shorthand. -->
<!-- e.g. "- inngest/inngest#123" -->
<!-- Feel free to remove this section if there are no applicable related
links.-->
- inngest/inngest#1077
  • Loading branch information
jpwilliams committed Jan 30, 2024
1 parent d117510 commit 4d52f01
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-owls-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Make `data.error` parsing for `inngest/function.failed` more resilient
4 changes: 2 additions & 2 deletions packages/inngest/etc/inngest.api.md

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

22 changes: 15 additions & 7 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ export type GetEvents<T extends Inngest.Any> = T extends Inngest<infer U>
? EventsFromOpts<U>
: never;

export const failureEventErrorSchema = z.object({
name: z.string(),
message: z.string(),
stack: z.string().optional(),
cause: z.string().optional(),
status: z.number().optional(),
});
export const failureEventErrorSchema = z
.object({
name: z.string().trim().optional(),
error: z.string().trim().optional(),
message: z.string().trim().optional(),
stack: z.string().trim().optional(),
})
.catch({})
.transform((val) => {
return {
name: val.name || "Error",
message: val.message || val.error || "Unknown error",
stack: val.stack,
};
});

export type MiddlewareStack = [
InngestMiddleware<MiddlewareOptions>,
Expand Down

0 comments on commit 4d52f01

Please sign in to comment.