Skip to content

fix: preserve err.code in SerializedError cross-process serialization - #42534

Closed
Wu Shuwen (dajiaohuang) wants to merge 1 commit into
microsoft:mainfrom
dajiaohuang:fix/preserve-err-code
Closed

fix: preserve err.code in SerializedError cross-process serialization#42534
Wu Shuwen (dajiaohuang) wants to merge 1 commit into
microsoft:mainfrom
dajiaohuang:fix/preserve-err-code

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

APIRequestContext errors were losing the err.code structured field after cross-process serialization.

Root Cause

serializeError in both client/errors.ts and server/errors.ts only preserved message, stack, and name from error objects. The code field (common in Node.js network errors like ECONNREFUSED, ECONNRESET, etc.) was silently dropped.

Fix

  1. Added code?: string to the SerializedError.error type in packages/protocol/src/structs.d.ts
  2. Updated serializeError in both client and server to include e.code when present
  3. Updated parseError in both client and server to restore the code field on the deserialized error

Testing

This fix can be verified with the reproduction script from issue #42532:

import { request } from '@playwright/test'

const context = await request.newContext()
try {
  await context.post('http://127.0.0.1:1/', { data: {} })
} catch (err) {
  console.log('code:', err.code)  // Now properly shows 'ECONNREFUSED'
}

Related Issue

Fixes #42532

APIRequestContext errors were losing structured fields (err.code)
after cross-process serialization because serializeError only
preserved message, stack, and name.

This adds code preservation to both serializeError and parseError
in both client and server error handling modules.

Fixes microsoft#42532
@dgozman

Copy link
Copy Markdown
Collaborator

Closing in favor of #42562.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: APIRequestContext errors lose structured fields (err.code is undefined) after cross-process serialization

2 participants