fix(shared): throw UnknownAttachmentDataError for unhandled AttachmentDescriptor payloads - #588
Conversation
502e858 to
20e609a
Compare
…tDescriptor payloads Signed-off-by: abhayrajjais01 <abhayrajjais01@users.noreply.github.com>
20e609a to
7c50eab
Compare
elribonazo
left a comment
There was a problem hiding this comment.
Nothing that you added should have any effect on the setup.ts files, why did you add that?
| @@ -0,0 +1,8 @@ | |||
|
|
|||
| import { Buffer } from 'buffer'; | |||
There was a problem hiding this comment.
Is that needed really? Nothing that u added has any effect on this, am I wrong?
There was a problem hiding this comment.
I added tests/setup.ts only because vitest.config.js already references ./tests/setup.ts but that file was missing on main -> I can keep an empty/minimal setup file for that path, without the polyfill,
Buffer was already used in MessageAttachment, and Vitest’s jsdom env still runs under Node where Buffer is normally global, so I wil remove the buffer import and global assignment
There was a problem hiding this comment.
@elribonazo ,
what should i do??
1st - remove the Buffer and if-else block and write a tiny placeholder file so vitest.config.js still has a real ./tests/setup.ts
or
delete setup.ts and remove the setupFiles: [tests/setup.ts] line from vitest.config.js so Vitest doesn’t point at a missing file??
|
Thanks for your contribution, @abhayrajjais01! The change itself is correct and clean. // TODO better error
throw new Error("Unhandled attachment");The domain layer already defines The test is clean — it constructs a header-only The
|
Remove Buffer setup code for testing environment. Signed-off-by: Abhayraj Jaiswal <abhayraj916146@gmail.com>
|
@yshyn-iohk, |
|
|
@abhayrajjais01 please check your commit signatures |
| @@ -0,0 +1,2 @@ | |||
| // packages/shared/domain/tests/setup.ts | |||
|
Closing due to inactivity |
|
hi @elribonazo, |



Description
AttachmentDescriptor.extractJSONthrew a genericError("Unhandled attachment")for payloads that were neither valid base64 JSON nor a recognizablejsonattachment shape. The domain layer already definesMercuryError.UnknownAttachmentDataError, but this path did not use it, so callers could not reliably branch on Mercury’s typed errors.This PR throws
UnknownAttachmentDataErrorfrom that fallback path with a short message describing the expected shapes, and adds a Vitest regression test (header-only attachment data) that expectsMercuryError.UnknownAttachmentDataError.Files:
packages/shared/domain/src/models/MessageAttachment.ts,packages/shared/domain/tests/setup.ts,packages/shared/domain/tests/MessageAttachment.test.ts.Alternatives Considered (optional)
Error: Preserves oldinstanceof Errorbehavior but loses the domain error type and is inconsistent with existingMercuryerror classes.UnknownAttachmentDataErroralready matches the semantic.Checklist