Skip to content

Commit d763028

Browse files
committed
fix: dont prevent execution when capturing async function
1 parent a14ee27 commit d763028

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

e2e/capture.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ test('should capture front-end bug in nextjs example', async ({ page }) => {
6161
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
6262
await page.goto(getBaseUrl(NEXTJS_PORT));
6363
await page.reload()
64+
await waitMs(3_000)
6465

6566
// Find the input
6667
await page.locator('input').fill('wrong')
@@ -73,7 +74,7 @@ test('should capture front-end bug in nextjs example', async ({ page }) => {
7374
const consoleLogsArgs = await consolePromise.args()
7475
// expect(await consoleLogsArgs[0]?.jsonValue()).toContain('[🐛 post] https://www.useflytrap.com/api/v1/captures')
7576

76-
await waitMs(10_000);
77+
await waitMs(3_000);
7778

7879
// Check the API for the capture
7980
const capturesAfter = await fetchCaptures('sk_Y8dYLe5VoNJfDI_CPEqF8AqMTEwWAvTwBi7Ml-pN9bzWsgsP');
@@ -89,7 +90,7 @@ test('should capture front-end bug in sveltekit example', async ({ page }) => {
8990
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
9091
await page.goto(getBaseUrl(SVELTE_PORT));
9192
await page.reload()
92-
await waitMs(1000)
93+
await waitMs(3_000)
9394

9495
// Find the input
9596
await page.locator('input').fill('wrong')
@@ -116,7 +117,7 @@ test('should capture front-end bug in nuxt example', async ({ page }) => {
116117
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
117118
await page.goto(getBaseUrl(NUXT_PORT));
118119
await page.reload()
119-
await waitMs(1000)
120+
await waitMs(3_000)
120121

121122
// Find the input
122123
await page.locator('input').fill('wrong')

examples/with-nuxt/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"useflytrap": "workspace:*"
1313
},
1414
"devDependencies": {
15-
"@types/node": "^18",
1615
"nuxt": "^3.5.1"
1716
}
1817
}

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,18 @@ export function useFlytrapFunction<
6565
*/
6666
saveErrorForFunction(opts.id, error)
6767
log.info('capture', `Captured error in async function with ID "${opts.id}".`, { error })
68-
const { error: saveError } = await utilTryCatch(
69-
getFlytrapStorage().saveCapture(_executingFunctions, _functionCalls, error as Error)
70-
)
71-
if (saveError) {
72-
console.error(
73-
createHumanLog({
74-
event: 'capture_failed',
75-
explanation: 'api_capture_error_response',
76-
solution: 'try_again_contact_us'
77-
}).toString()
78-
)
79-
console.error(saveError)
80-
}
68+
getFlytrapStorage()
69+
.saveCapture(_executingFunctions, _functionCalls, error as Error)
70+
.catch((saveError) => {
71+
console.error(
72+
createHumanLog({
73+
event: 'capture_failed',
74+
explanation: 'api_capture_error_response',
75+
solution: 'try_again_contact_us'
76+
}).toString()
77+
)
78+
console.error(saveError)
79+
})
8180

8281
throw error
8382
}
@@ -125,18 +124,17 @@ export function useFlytrapFunction<
125124
*/
126125
saveErrorForFunction(opts.id, error)
127126
log.info('capture', `Captured error in function with ID "${opts.id}".`, { error })
128-
const { error: saveError } = utilTryCatchSync(() =>
129-
getFlytrapStorage().saveCapture(_executingFunctions, _functionCalls, error as Error)
130-
)
131-
if (saveError) {
132-
const errorLog = createHumanLog({
133-
event: 'capture_failed',
134-
explanation: 'generic_unexpected_error',
135-
solution: 'try_again_contact_us'
127+
getFlytrapStorage()
128+
.saveCapture(_executingFunctions, _functionCalls, error as Error)
129+
.catch((saveError) => {
130+
const errorLog = createHumanLog({
131+
event: 'capture_failed',
132+
explanation: 'generic_unexpected_error',
133+
solution: 'try_again_contact_us'
134+
})
135+
console.error(errorLog.toString())
136+
console.error(saveError)
136137
})
137-
console.error(errorLog.toString())
138-
console.error(saveError)
139-
}
140138

141139
throw error
142140
}

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
useflytrap: fileURLToPath(new URL('./src/index.ts', import.meta.url).href)
1111
}
1212
},
13+
// @ts-ignore
1314
test: {
1415
coverage: {
1516
'100': true,

0 commit comments

Comments
 (0)