Skip to content

fix: report invalid SQS/SNS policy values as diagnostics - #46

Merged
VisualBean merged 1 commit into
ByteBardOrg:vnextfrom
bielu:fix/aws-policy-parse-diagnostics
Oct 17, 2026
Merged

VisualBean merged 1 commit into
ByteBardOrg:vnextfrom
bielu:fix/aws-policy-parse-diagnostics

Conversation

@bielu

@bielu bielu commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A malformed value in an SQS or SNS policy statement crashes the reader instead of producing a diagnostic:

bindings:
  sqs:
    queue:
      name: myQueue
      policy:
        statements:
          - effect: Allow
            action:
              foo: bar
System.ArgumentException: An error occured while parsing a StringOrStringList node. Node should contain a string value or a list of strings.

StringOrStringList.Parse, Principal.Parse and Condition.Parse (both the SQS and SNS copies) threw ArgumentException. The field parser and BindingDeserializer.LoadBindings only catch AsyncApiException, so the exception escaped ReadFragment/Read and the caller got no ReadResult/diagnostics at all.

An empty principal map (principal: {}) also threw InvalidOperationException from mapNode.First().

Change

  • The Parse methods now throw AsyncApiReaderException with the parsing context, so the error is recorded in diagnostic.Errors with a pointer, and reading continues.
  • Principal.Parse uses FirstOrDefault() and treats an empty map as an invalid principal.
  • The StringOrStringList constructor still throws ArgumentException for direct API misuse; only parsing changed.

Tests

Added AwsPolicyParsing_Should (10 cases) covering invalid action, principal (scalar other than *, unknown key, empty map, list) and condition values for SQS and SNS. All 10 fail on vnext and pass with this change; the full suite passes on net8.0/net9.0/net10.0.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting for malformed SNS and SQS policy values, including details about where parsing failed.
    • Empty or invalid principal maps now produce clear parsing errors instead of causing unexpected failures.
    • Invalid string-or-list values now report a parsing error with node context.
  • Tests
    • Added coverage for malformed action, principal, and condition values in SNS and SQS channel bindings.

StringOrStringList, Principal and Condition threw ArgumentException from
their Parse methods. The reader only catches AsyncApiException, so a
malformed policy statement (e.g. `action` given as a map) escaped
ReadFragment/Read instead of becoming a diagnostic. An empty principal
map also threw InvalidOperationException from First().

Parse now throws AsyncApiReaderException with the parsing context, and
an empty principal map is rejected through the same path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bbf4b790-2916-424f-b74e-308967a7f213
📥 Commits

Reviewing files that changed from the base of the PR and between eb68984 and cd07ef7.

📒 Files selected for processing: 6
  • src/ByteBard.AsyncAPI.Bindings/Sns/Condition.cs
  • src/ByteBard.AsyncAPI.Bindings/Sns/Principal.cs
  • src/ByteBard.AsyncAPI.Bindings/Sqs/Condition.cs
  • src/ByteBard.AsyncAPI.Bindings/Sqs/Principal.cs
  • src/ByteBard.AsyncAPI.Bindings/StringOrStringList.cs
  • test/ByteBard.AsyncAPI.Tests/Bindings/AwsPolicyParsing_Should.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

SNS and SQS binding parsers now report invalid policy values with AsyncApiReaderException and include parse-node context. Tests cover malformed action, principal, and condition fields.

Changes: AWS policy parsing

Layer / File(s) Summary
Contextual parse errors
src/ByteBard.AsyncAPI.Bindings/Sns/Condition.cs, src/ByteBard.AsyncAPI.Bindings/Sns/Principal.cs, src/ByteBard.AsyncAPI.Bindings/Sqs/Condition.cs, src/ByteBard.AsyncAPI.Bindings/Sqs/Principal.cs, src/ByteBard.AsyncAPI.Bindings/StringOrStringList.cs, test/ByteBard.AsyncAPI.Tests/Bindings/AwsPolicyParsing_Should.cs
Invalid parser inputs now raise contextual AsyncApiReaderException errors. Principal map parsing rejects empty maps. Tests verify that malformed SQS and SNS policy fields produce one diagnostic with the expected type name.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: visualbean

Merge Risk: ⚪ Minimal · up to cd07e

The malformed policy values examined are reported as diagnostics. No identified issue needs resolution before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: malformed SQS and SNS policy values now produce diagnostics.
Description check Passed The description clearly explains the problem, implementation changes, edge-case handling, and test coverage. It does not use the template headings or provide a related issue, but it is mostly complete…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the problem, implementation changes, edge-case handling, and test coverage. It does not use the template headings or provide a related issue, but it is mostly complete and directly relevant.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bielu
bielu marked this pull request as ready for review October 17, 2026 17:32
@VisualBean
VisualBean merged commit da8a261 into ByteBardOrg:vnext Oct 17, 2026
11 checks passed
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