Skip to content

Commit d68e5c7

Browse files
committed
fix: make function encrypt the error aswell, fix replay args mistake
1 parent 53987ed commit d68e5c7

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

e2e/replay.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, test } from "@playwright/test";
22
import { REPLAY_NEXTJS_PORT, getBaseUrl, waitMs } from "./util";
33

4-
test.only('should replay front-end bug in nextjs example', async ({ page }) => {
4+
test('should replay front-end bug in nextjs example', async ({ page }) => {
55
// const capturesBefore = await fetchCaptures('sk_Y8dYLe5VoNJfDI_CPEqF8AqMTEwWAvTwBi7Ml-pN9bzWsgsP');
66
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
77
await page.goto(getBaseUrl(REPLAY_NEXTJS_PORT));

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const config: PlaywrightTestConfig = {
7676
env: {
7777
PORT: REPLAY_NEXTJS_PORT.toString(),
7878
FLYTRAP_MODE: 'replay',
79-
FLYTRAP_CAPTURE_ID: 'e75be9f6-ad3a-4c1d-9848-9dc50e74583e'
79+
FLYTRAP_CAPTURE_ID: 'bbcffc6b-13dc-4be5-b458-6b6eb1597ba9',
8080
},
8181
timeout: 120 * 1000,
8282
reuseExistingServer: !process.env.CI,

src/core/encryption.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,24 @@ export async function encryptCapture(
251251
const linkedCalls = addLinksToCaptures(calls, { args, outputs })
252252
const linkedFunctions = addLinksToCaptures(functions, { args, outputs })
253253

254-
const stringifyResult = Result.all(safeStringify(args), safeStringify(outputs))
254+
const serializedError = serializeError(error)
255+
256+
const stringifyResult = Result.all(
257+
safeStringify(args),
258+
safeStringify(outputs),
259+
error !== undefined ? safeStringify(serializedError) : Ok(undefined)
260+
)
255261

256262
if (stringifyResult.err) {
257263
return stringifyResult
258264
}
259265

260-
const stringifiedErrorResult =
261-
error === undefined ? Ok(undefined) : safeStringify(serializeError(error))
262-
263-
const [stringifiedArgs, stringifiedOutputs] = stringifyResult.val
266+
const [stringifiedArgs, stringifiedOutputs, stringifiedError] = stringifyResult.val
264267

265268
const encryptionResult = Result.all(
266269
await encrypt(publicKey, stringifiedArgs),
267270
await encrypt(publicKey, stringifiedOutputs),
268-
stringifiedErrorResult
271+
stringifiedError !== undefined ? await encrypt(publicKey, stringifiedError) : Ok(undefined)
269272
)
270273

271274
if (encryptionResult.err) {
@@ -274,8 +277,6 @@ export async function encryptCapture(
274277

275278
const [encryptedArgs, encryptedOutputs, encryptedError] = encryptionResult.val
276279

277-
const serializedError = serializeError(error)
278-
279280
return Ok({
280281
capturedUserId,
281282
projectId,

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ export function uff<T extends AnyFunction>(func: T, id: string | null = null): T
126126
}
127127

128128
// @ts-expect-error: because of NO-OP
129-
const replayArgs = findLastInvocationById(id, currentLoadedCaptureResult.val)
129+
const lastInvocation = findLastInvocationById(id, currentLoadedCaptureResult.val)
130130

131-
if (!replayArgs) {
131+
if (!lastInvocation) {
132132
const context = null
133133
return func.apply(context ?? this, args)
134134
}
135135

136136
// Merge replay args & real args
137+
const replayArgs = lastInvocation.args
137138
const mergedArgs = fillUnserializableFlytrapValues(replayArgs, args)
138139
// @ts-expect-error for some reason `this as any` still gives error
139140
return func.apply(context ?? this, mergedArgs)

0 commit comments

Comments
 (0)