Skip to content

fix(concerto-core): throw ValidationException for map type violations (closes #1649) - #1650

Open
Shawnn08 wants to merge 1 commit into
accordproject:mainfrom
Shawnn08:fix/resource-validator-map-validation-exception
Open

Shawnn08 wants to merge 1 commit into
accordproject:mainfrom
Shawnn08:fix/resource-validator-map-validation-exception

Conversation

@Shawnn08

Copy link
Copy Markdown
Contributor

Closes #1649

Ensures that ResourceValidator.visitMapDeclaration and ResourceValidator.checkMapType throw ValidationException instead of generic Error when validating Map keys, values, and instance types.

Changes

  • Replaced generic throw new Error(...) with throw new ValidationException(...) across all map data type branches (String, DateTime, Boolean, Integer, Long, Double) in checkMapType.
  • Replaced generic throw new Error(...) with throw new ValidationException(...) in visitMapDeclaration when input is not an instance of Map.
  • Added defensive try/catch around JSON.stringify(obj) in visitMapDeclaration falling back to String(obj) to safely handle circular objects or BigInt.
  • Removed redundant !isFinite(value) check in Integer/Long validation since Number.isInteger already excludes non-finite values.
  • Updated Map failure tests in test/serializer/maptype/serializer.js and test/serializer/resourcevalidator.js to assert ValidationException.
  • Added test coverage in test/serializer/resourcevalidator.js verifying that non-Map objects (null, undefined, {}, { a: 1 }) throw ValidationException.
  • Added backward compatibility test verifying ValidationException instanceof Error.

Flags

  • Fully backward-compatible: ValidationException inherits from BaseFileException which extends Error, so existing consumer code with catch (err) or err instanceof Error remains unaffected.

Screenshots or Video

N/A (Backend serialization logic and tests)

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

…closes accordproject#1649)

Signed-off-by: Shreyansh Giri <girilakshmi91@gmail.com>
@mira-accord-project

Copy link
Copy Markdown

Thanks for this pull request, Shawnn08. Switching the Map validation errors in ResourceValidator to ValidationException brings them in line with the other validators, and the updated tests assert the exception type, which makes the change easy to check. Jonathan Casey, Jamie Shorten and Ertugrul Karademir have been asked to review. A maintainer will go through the change and reply on this thread. Thank you for the contribution.


Posted automatically by Mira, an Accord Project agent. A maintainer will follow up; they make the decisions on this.

@mira-accord-project mira-accord-project Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, Shawnn08. This does what #1649 asks: map type violations in checkMapType and visitMapDeclaration now throw ValidationException (still an Error, so existing catch blocks keep working), and the JSON.stringify fallback stops a circular value from hiding the real error. Dropping isFinite from the Integer/Long check is safe, since Number.isInteger already rejects NaN and Infinity. The tests assert the new type, cover non-Map input including null and undefined, and check instanceof Error. I found nothing that needs changing, and CI is green. It now needs a maintainer's approval.

No problems found.


Automated review by Mira, an Accord Project agent, at 7a6d4cd. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(concerto-core): ResourceValidator throws generic Error instead of ValidationException for Map validation

1 participant