Skip to content

fix(pluto): improve onlyOne() error message with diagnostic context#651

Open
A-Chronicle wants to merge 3 commits into
hyperledger-identus:mainfrom
A-Chronicle:fix/pluto-onlyone-error-message
Open

fix(pluto): improve onlyOne() error message with diagnostic context#651
A-Chronicle wants to merge 3 commits into
hyperledger-identus:mainfrom
A-Chronicle:fix/pluto-onlyone-error-message

Conversation

@A-Chronicle

@A-Chronicle A-Chronicle commented May 24, 2026

Copy link
Copy Markdown
Contributor

Description

The onlyOne() method in Pluto.ts throws a generic new Error("something wrong") with no diagnostic context, making it impossible to identify what query failed or why.

Changes:

  • onlyOne() now accepts an optional context string to identify the caller
  • Distinguishes between empty results (arr.length === 0) and multiple results
  • Reports the actual count when >1 result is found
  • Passes context from getPairByDID() and getPairByName() callers
  • Adds diagnostic context to getAllMediators() error messages (was bare throw new Error() with no message)
  • Adds comprehensive tests for error paths in onlyOne() and getAllMediators()

Fixes #648

Alternatives Considered

  • Using a typed PlutoError subclass — overkill for a private helper; callers already handle errors appropriately
  • Making onlyOne() public — unnecessary; only used internally

Checklist

  • My PR follows the contribution guidelines of this project
  • My PR is free of third-party dependencies that dont 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

@A-Chronicle A-Chronicle requested a review from a team as a code owner May 24, 2026 08:15
The onlyOne() method in Pluto threw a generic Error("something wrong") with no context about what was being looked up or why it failed.

Changes:
- Accept optional context string to identify the caller and query
- Distinguish between empty results (arr.length === 0) and null item
- Report the actual count when multiple results found
- Pass context from getPairByDID() and getPairByName() callers

Fixes hyperledger-identus#648

Signed-off-by: A-Chronicle <chaubeyanshika319@gmail.com>
@A-Chronicle A-Chronicle force-pushed the fix/pluto-onlyone-error-message branch from 5dedf82 to de22912 Compare May 24, 2026 08:21

@abhigyan1102 abhigyan1102 left a comment

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.

Nice fix! The split between empty vs. multiple results with the actual count is way better than the old "something wrong" message.

One thing I noticed — getAllMediators() at L743 and L751 has the same problem but worse: throw new Error() with completely empty messages. Might be worth adding context there too, either in this PR or a follow-up.

@A-Chronicle

A-Chronicle commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

Nice fix! The split between empty vs. multiple results with the actual count is way better than the old "something wrong" message.

One thing I noticed — getAllMediators() at L743 and L751 has the same problem but worse: throw new Error() with completely empty messages. Might be worth adding context there too, either in this PR or a follow-up.

Thankyou @abhigyan1102 for the review , I will surely look into the issues you have mentioned ,looking forward to fix them soon maybe in a follow up pr probably.

getAllMediators() had bare throw new Error() calls with no message
at two failure points, making debugging impossible.

Changes:
- Missing link error now reports the hostId and which link is missing
- Empty DID error reports hostId and which DIDs resolved to null

Signed-off-by: A-Chronicle <chaubeyanshika319@gmail.com>
@A-Chronicle

Copy link
Copy Markdown
Contributor Author

@abhigyan1102 @elribonazo @yshyn-iohk I have addressed addressed the getAllMediators() issue in this updated PR, now it is ready to get reviewed.

…) error context

- Add JSDoc comment to onlyOne() explaining context parameter and failure modes
- Add inline comments to getAllMediators() error throws explaining each check
- Add tests verifying onlyOne() throws descriptive errors for empty/multiple results
- Add tests verifying getAllMediators() throws descriptive errors for missing links/DIDs

Signed-off-by: A-Chronicle <chaubeyanshika319@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

@abhigyan1102

Copy link
Copy Markdown
Contributor

Looks good! the getAllMediators() context - the boolean breakdown in the error message (host: true, mediator: true, routing: false) is a nice touch for debugging! Tests looks solid too. LGTM

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.

chore: improve Pluto.onlyOne() error message to include diagnostic context

2 participants