Repository navigation
Post E2EE worker errors as plain objects - #2294
Conversation
Safari before version 17 cannot structured-clone an Error object. The postMessage call in the worker threw a DataCloneError, and the page never received the encryption error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
This PR bumps
|
There was a problem hiding this comment.
Devin Review found 1 potential issue.
2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| error: | ||
| error instanceof Error | ||
| ? { name: error.name, message: error.message } | ||
| : { name: 'Error', message: String(error) }, |
There was a problem hiding this comment.
🔴 Failed decryption stalls incoming data
On Safari 16, workerLogger.error posts the raw error for the first decryption failure when error logging is enabled. That post throws before the worker replies. handleDataMessage keeps its lock while waiting, so later packets never run.
Learn more
The worker must send a reply with the request ID so handleEncryptedData can settle its pending promise. DataCryptor.decrypt throws a native Error when the required key is unavailable. The first failure for that participant reaches the error log, and the worker logger posts the entire context, including that native error. Safari 16 throws a DataCloneError there before the new plain-object reply is sent. Incoming packets share a lock that handleDataMessage releases only after the pending decryption settles.
Example: A Safari 16 participant with default logging receives an encrypted packet before the matching key is installed. That packet never finishes processing, and installing the key does not free the lock for later packets.
Recommended fix: Serialize the caught error once before logging, then use that plain object in both the log context and the UUID reply. Add a worker-side test with a postMessage stub that rejects native errors and verify that the first failed decryption still sends its UUID reply.
Was this helpful? React with 👍 or 👎 to provide feedback.
size-limit report 📦
|
| error: | ||
| error instanceof Error | ||
| ? { name: error.name, message: error.message } | ||
| : { name: 'Error', message: String(error) }, |
There was a problem hiding this comment.
suggestion: It might also be worth capturing error.stack here too, so errors can be traced across the worker boundary? Something like:
// e2ee.worker.ts (encrypt/decrypt request path)
error instanceof Error
? { name: error.name, message: error.message, stack: error.stack }
: { name: 'Error', message: String(error) },
// E2eeManager.ts
const error = new Error(data.error.message);
error.name = data.error.name;
if (data.error.stack) {
error.stack = data.error.stack;
}Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The worker forwards each log call to the page with postMessage. A raw Error in the log context made that call throw on Safari before version 17. In the data decryption path the log call runs before the reply, so the pending request never settled. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The test added in #2294 declared its own `replies`, which shadows the suite's, and its afterEach resets postMessage to a no-op, which would stop the barrier from ever seeing its echo. Install the recorder before each test and let the new test push into the shared replies.
Safari before version 17 cannot structured-clone an
Errorobject. The E2EE worker posts anErrorto the page for each cryptor error. On these Safari versions thepostMessagecall throws aDataCloneError, and the page never receives theEncryptionErrorevent.The worker now posts the name and the message as a plain object.
E2EEManagerbuilds theErrorfrom it. The same applies to the errors of data encryption and decryption requests.🤖 Generated with Claude Code