Skip to content

feat: Add help text for function argument validation errors#2291

Open
Vedthakar wants to merge 1 commit intocedar-policy:mainfrom
Vedthakar:issue-834-function-argument-validation-help
Open

feat: Add help text for function argument validation errors#2291
Vedthakar wants to merge 1 commit intocedar-policy:mainfrom
Vedthakar:issue-834-function-argument-validation-help

Conversation

@Vedthakar
Copy link
Copy Markdown
Contributor

@Vedthakar Vedthakar commented Apr 5, 2026

Description of changes

Closes #834

This PR adds help text to FunctionArgumentValidationError so validator errors for invalid extension function arguments include human-readable format guidance when available.

Previously, these errors only surfaced a generic parse failure message. With this change, invalid arguments to extension functions such as decimal, ip, datetime, and duration can now also include help text describing the expected input format.

What changed

  • Updated extension argument validation to return structured validation errors instead of only raw strings
  • Added optional help text propagation into FunctionArgumentValidationError
  • Surfaced upstream parser help text when available, with fallback help text for cases where none is provided
  • Added coverage for:
    • ip
    • decimal
    • datetime
    • duration
    • public API behavior
    • FFI behavior

This directly addresses the request in #834 to make these validator errors more actionable by explaining what valid extension function inputs should look like.

Issue #, if available

Closes #834

Checklist for requesting a review

The change in this PR is:

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).
  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).
  • A bug fix or other functionality change requiring a patch to cedar-policy.
  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)
  • A change (breaking or otherwise) that only impacts unreleased or experimental code.

I confirm that this PR:

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).
  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec:

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-spec, and how you have tested that your updates are correct.)
  • Requires updates, but I do not plan to make them in the near future. (Make sure that your changes are hidden behind a feature flag to mark them as experimental.)
  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I confirm that docs.cedarpolicy.com:

  • Does not require updates because my change does not impact the Cedar language specification.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-docs. PRs should be targeted at a staging-X.Y branch, not main.)
  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

@Vedthakar Vedthakar force-pushed the issue-834-function-argument-validation-help branch from b741ca8 to 3ecaf9b Compare April 5, 2026 15:51
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Coverage Report

Head Commit: 3ecaf9bbe1a9bebb773c74b1e861af6f4a657b8e

Base Commit: 5039325c536b0f6bb7de9d0b88734450b8a68f4b

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 100.00%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/validator/diagnostics.rs 🟢 2/2 100.00%
cedar-policy-core/src/validator/diagnostics/validation_errors.rs 🟢 3/3 100.00%
cedar-policy-core/src/validator/extension_schema.rs 🟢 7/7 100.00%
cedar-policy-core/src/validator/extensions/datetime.rs 🟢 22/22 100.00%
cedar-policy-core/src/validator/extensions/decimal.rs 🟢 11/11 100.00%
cedar-policy-core/src/validator/extensions/ipaddr.rs 🟢 11/11 100.00%
cedar-policy-core/src/validator/typecheck.rs 🟢 3/3 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 87.56%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4722/5102 92.55% 92.55%
cedar-policy 🟡 4229/5353 79.00% 78.95%
cedar-policy-cli 🟡 1136/1581 71.85% 71.85%
cedar-policy-core 🟢 24042/27319 88.00% 87.99%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6752/7262 92.98% 92.98%
cedar-wasm 🔴 0/28 0.00% 0.00%

Copy link
Copy Markdown
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

help message text looks reasonable. might consider pushing it up into the main extension parsing code

Comment thread cedar-policy-core/src/validator/extensions/datetime.rs Outdated
Comment thread cedar-policy/src/test/test.rs
Signed-off-by: Ved Thakar <ved06.thakar@gmail.com>
@Vedthakar Vedthakar force-pushed the issue-834-function-argument-validation-help branch from 3ecaf9b to d7326fe Compare April 6, 2026 23:00
Copy link
Copy Markdown
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

Looks good. Just one more possible tweak (if it works) and then you'll need to run cargo fmt

Comment thread cedar-policy-core/src/validator/diagnostics/validation_errors.rs
@john-h-kastner-aws
Copy link
Copy Markdown
Contributor

Hi! I think this PR is good-to-go after once you push a quick cargo fmt

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.

Add help text for FunctionArgumentValidationError

3 participants