-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance safe() overloads #2
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 |
|---|---|---|
|
|
@@ -328,6 +328,15 @@ describe('client safe()', () => { | |
| expectTypeOf(err.code).toEqualTypeOf<ErrorCode | InternalCode>() | ||
| } | ||
| }) | ||
|
|
||
| it('captures synchronous throws from function input', async () => { | ||
| const [data, err] = await client.safe(() => { | ||
| throw new Error('boom') | ||
| }) | ||
|
|
||
| expect(data).toBeNull() | ||
| expect(err?.code).toBe('errata.unknown_error') | ||
| }) | ||
|
Comment on lines
+332
to
+339
|
||
| }) | ||
|
|
||
| describe('client onUnknown hook', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,16 @@ describe('errata basics', () => { | |
| expectTypeOf(value).toEqualTypeOf<number>() | ||
| } | ||
| }) | ||
|
|
||
| it('handles synchronous throw from function input', async () => { | ||
| const [value, err] = await errors.safe(() => { | ||
| throw new Error('boom') | ||
| }) | ||
|
|
||
| expect(value).toBeNull() | ||
| expect(err).toBeInstanceOf(errors.ErrataError) | ||
| expect(err?.code).toBe('errata.unknown_error') | ||
| }) | ||
|
Comment on lines
+213
to
+221
|
||
| }) | ||
|
|
||
| describe('onUnknown hook', () => { | ||
|
|
||
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.
The comment has a grammatical issue. "Promise/helper" should be "Promise helper or function" to properly describe that this function accepts both promises and functions.