Skip to content

Fix/shared unknown attachment error - #642

Open
abhayrajjais01 wants to merge 10 commits into
hyperledger-identus:mainfrom
abhayrajjais01:fix/shared-unknown-attachment-error
Open

Fix/shared unknown attachment error#642
abhayrajjais01 wants to merge 10 commits into
hyperledger-identus:mainfrom
abhayrajjais01:fix/shared-unknown-attachment-error

Conversation

@abhayrajjais01

Copy link
Copy Markdown

Description

AttachmentDescriptor.extractJSON threw a generic Error("Unhandled attachment") for payloads that were neither valid base64 JSON nor a recognizable json attachment shape. The domain layer already defines MercuryError.UnknownAttachmentDataError, but this path did not use it, so callers could not reliably branch on Mercury’s typed errors.

This PR throws UnknownAttachmentDataError from that fallback path with a short message describing the expected shapes, and adds a Vitest regression test (header-only attachment data) that expects MercuryError.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)

  • Keep Error: Preserves old instanceof Error behavior but loses the domain error type and is inconsistent with existing Mercury error classes.
  • New error class: Unnecessary; UnknownAttachmentDataError already matches the semantic.

Checklist

  • My PR follows the contribution guidelines of this project
  • My PR is free of third-party dependencies that don't comply with the Allowlist
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked the PR title to follow the conventional commit specification

abhayrajjais01 and others added 6 commits May 3, 2026 11:41
…tDescriptor payloads

Signed-off-by: abhayrajjais01 <abhayrajjais01@users.noreply.github.com>
Remove Buffer setup code for testing environment.

Signed-off-by: Abhayraj Jaiswal <abhayraj916146@gmail.com>
Remove unnecessary comment from setup file.

Signed-off-by: Abhayraj Jaiswal <abhayraj916146@gmail.com>
@abhayrajjais01
abhayrajjais01 requested a review from a team as a code owner May 20, 2026 06:41
Comment thread packages/shared/domain/tests/setup.ts Outdated
@@ -0,0 +1,2 @@

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

Comment thread packages/shared/domain/tests/setup.ts Outdated
@@ -0,0 +1 @@
// intentionally empty – required by vitest.config.js setupFiles

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't create / commit the file please...

Signed-off-by: Abhayraj Jaiswal <abhayraj916146@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants