Skip to content

fix: pass a payload that is not JSON to a custom mapper unchanged - #387

Merged
hamzahalq merged 1 commit into
releases/r10.0-developfrom
hamza/fix/legacy-mapper-non-json-input
Oct 20, 2026
Merged

hamzahalq merged 1 commit into
releases/r10.0-developfrom
hamza/fix/legacy-mapper-non-json-input

Conversation

@hamzahalq

Copy link
Copy Markdown
Contributor

Before a mapper other than the rules-based one runs, Bitween parses the input as JSON to write in __partner__ and __globals__. On XML or CSV that parse threw, so the exchange failed before its mapper ran. Traxis prod hit it this morning: 854 SkyNet returns (XML, read by a custom mapper) failed with Unexpected character encountered while parsing value: <.

Now a payload that is not JSON is not enriched and reaches the mapper as it arrived, like a JSON array already did.

  • The golden files change only in === enriched, for the 20 inputs that are not valid JSON.
  • caveats.md and exchange-pipeline.md no longer describe the failure.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: simplify9/coderabbit/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: fce2675b-9a6c-4bcd-ab87-66db37ea05ff
📥 Commits

Reviewing files that changed from the base of the PR and between 539dc68 and 5e634f0.

📒 Files selected for processing: 24
  • SW.Bitween.Api/Services/MapperEnrichment.cs
  • SW.Bitween.Api/Services/XchangeService.cs
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-bom.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-deep.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-empty.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-invalid.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-trailing-content.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-trailing-garbage.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/json-whitespace-only.json.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/text-csv.txt.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-bom.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-cdata.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-dtd.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-entities.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-html-encoded.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-invalid-chars.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-invalid.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-namespaces.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-order.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-plain.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-trailing-content.xml.txt
  • SW.Bitween.UnitTests/PayloadParsing/Golden/expected/xml-utf16-declaration.xml.txt
  • docs/caveats.md
  • docs/exchange-pipeline.md

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

📜 Recent review details
⏰ Context from checks skipped due to timeout: 1
  • GitHub Check: build-and-unit-test
🔇 Additional comments: 1
SW.Bitween.Api/Services/MapperEnrichment.cs: 1

42-42: 🩺 Stability & Availability

The shared parser already handles parse failures.

ParsedPayload.TryGet catches parser exceptions, stores a failure sentinel, and returns false. The JsonReaderException catch in MapperEnrichment.Read then handles the fallback parse. The shared-parser path does not bypass this catch by throwing from TryGet.

📝 Summary

Summary

  • MapperEnrichment.Read now skips enrichment for invalid JSON.
  • Custom mappers receive XML, CSV, and other non-JSON payloads unchanged.
  • JSON object payloads still receive __partner__ and __globals__.
  • Documentation and golden files reflect this behavior.

Risk: risk:low

Security-sensitive areas: Existing enrichment can overwrite __partner__ and __globals__. No new security boundary changes.

Test coverage impact: Golden files cover malformed JSON, XML, CSV, BOM, and trailing-content inputs. Test execution results were not supplied.

Operational concerns: No migration or deployment steps are indicated. Rollback restores the previous preprocessing failures for non-JSON payloads.

MapperEnrichment.Read now returns null for JSON parse errors. Non-JSON payloads can proceed to custom mappers unchanged. Golden expectations and documentation reflect this behavior.

Changes: Mapper payload handling

Layer / File(s) Summary
Enrichment handling and payload expectations
SW.Bitween.Api/Services/MapperEnrichment.cs, SW.Bitween.Api/Services/XchangeService.cs, SW.Bitween.UnitTests/PayloadParsing/Golden/expected/*, docs/caveats.md, docs/exchange-pipeline.md
Read catches JsonReaderException and returns null. Comments clarify that only JSON objects are enriched. Golden expectations and documentation reflect handling of non-JSON payloads.

Priority: ⬆️ High

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

Change: Bug fix

Suggested labels: testing, risk:high

Suggested reviewers: samerzughul

Merge Risk: ⚪ Minimal · up to 5e634

The intended non-JSON mapper behavior is consistently reflected in the implementation, tests, and documentation.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (22 skipped: … 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 states the primary change: non-JSON payloads pass unchanged to custom mappers.
Description check Passed The description explains the prior JSON parsing failure, the new behavior, the production impact, and the related test and documentation updates.
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: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (22 skipped: 22 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
  • 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.

@hamzahalq
hamzahalq merged commit 9335470 into releases/r10.0-develop Oct 20, 2026
3 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