Skip to content

feat: improve js and python templates on send message error handling#2109

Open
derberg wants to merge 3 commits into
asyncapi:masterfrom
derberg:fixpysend
Open

feat: improve js and python templates on send message error handling#2109
derberg wants to merge 3 commits into
asyncapi:masterfrom
derberg:fixpysend

Conversation

@derberg

@derberg derberg commented Jun 1, 2026

Copy link
Copy Markdown
Member

fix #1858

I fixed not only in python but js as well as there was the same error

also added flag to constructors for user to disable this behaviour

also as agreed - agentic flow improved - changeset generation sucked so agents.md improved

Summary by CodeRabbit

  • New Features

    • WebSocket clients now forward send failures to registered error handlers and surface them to callers.
    • New per-client options to control send-error behavior: Python (raise_send_errors) and JavaScript (throwSendErrors).
    • Message validation flow made deterministic: successful validation returns immediately; aggregated validation errors are reported when none match.
  • Bug Fixes

    • Fixed silent suppression of send errors so failures are now detectable by client code.
  • Documentation

    • Updated usage examples and release hygiene guidance to document new behaviors.

@changeset-bot

changeset-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2299639

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@asyncapi/generator Minor
@asyncapi/generator-components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@asyncapi-bot

Copy link
Copy Markdown
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 20c013c6-7b7d-41e4-9b25-fda338b7b2d6

📥 Commits

Reviewing files that changed from the base of the PR and between 237585f and 2299639.

⛔ Files ignored due to path filters (2)
  • packages/components/test/components/__snapshots__/SendOperations.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/test/integration-test/__snapshots__/integration.test.js.javascript.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • AGENTS.md
  • packages/components/src/components/SendOperations.js
  • packages/templates/clients/websocket/javascript/components/Constructor.js
✅ Files skipped from review due to trivial changes (1)
  • AGENTS.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/templates/clients/websocket/javascript/components/Constructor.js
  • packages/components/src/components/SendOperations.js

📝 Walkthrough

Walkthrough

Updates WebSocket client generation to surface send errors instead of suppressing them. Python and JavaScript templates add constructor flags (raise_send_errors, throwSendErrors) to control whether send exceptions are re-thrown after error handlers run or are suppressed.

Changes

WebSocket Send Error Handling

Layer / File(s) Summary
Release Documentation
.changeset/fix-ws-swallowed-send-errors.md, AGENTS.md
Changeset documents the minor version bumps and the new error-propagation behavior. AGENTS.md adds release hygiene guidance mapping repo areas to published package names.
SendOperations Core Component
packages/components/src/components/SendOperations.js
Python instance methods forward caught send exceptions to handle_error(e) and re-throw when raise_send_errors is truthy. JavaScript instance methods forward errors to errorHandlers and conditionally re-throw based on throwSendErrors. JavaScript static send validates against compiled schemas, sends on first successful validation (or sends immediately if no schemas), and throws if no schema matches instead of silently suppressing.
Python Init/Constructor/Send Templates
packages/templates/clients/websocket/python/components/InitSignature.js, packages/templates/clients/websocket/python/components/Constructor.js, packages/templates/clients/websocket/python/components/Send.js
Generated Python __init__ now includes raise_send_errors: bool = True in both branches; constructor docstring and self.raise_send_errors assignment added. _send helper no longer swallows exceptions; serialization/send errors propagate to the caller.
JavaScript Constructor Template
packages/templates/clients/websocket/javascript/components/Constructor.js
Constructor template now accepts throwSendErrors (default true), stores it on the instance as this.throwSendErrors, and documents its role in controlling re-throw behavior after error handlers run.
Usage Examples and Documentation
packages/components/src/components/readme/Usage.js
Usage snippets updated: Python example shows send/receive wrapped in try/except to catch surfaced send exceptions; JavaScript example and comments adjusted and error log text changed to indicate connection-or-send failures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits format with 'feat:' prefix, uses imperative mood, clearly summarizes the main change (improving error handling in send templates), and appropriately triggers a MINOR/feature release.
Linked Issues check ✅ Passed All coding requirements from issue #1858 are met: send failures now raise exceptions instead of being swallowed in both Python and JavaScript templates, with opt-out configuration via constructor flags (raise_send_errors/throwSendErrors).
Out of Scope Changes check ✅ Passed All changes directly address the linked issue or improve related error-handling consistency; documentation updates (AGENTS.md, Usage.js) and changeset files are appropriately scoped to the core fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/templates/clients/websocket/python/components/InitSignature.js`:
- Around line 19-22: InitSignature generates an invalid Python signature when
queryParamsArguments is empty array (producing a stray comma); update the
early-return/conditional in InitSignature to treat both null/undefined and empty
arrays/strings as "no query params" (e.g., check for !queryParams ||
(Array.isArray(queryParams) && queryParams.length === 0) or queryParams === ''),
and ensure the template only inserts the comma when queryParamsArguments is
non-empty so the generated def __init__ signature (in InitSignature) is valid;
trace callers ClientClass → Constructor where queryParamsArray is produced from
getQueryParams to verify empty Map/object becomes an empty array handled by this
check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e098ac31-4188-44e5-8432-e24e2ed94f99

📥 Commits

Reviewing files that changed from the base of the PR and between 09f31e8 and f4a1853.

⛔ Files ignored due to path filters (8)
  • packages/components/test/components/__snapshots__/Readme.test.js.snap is excluded by !**/*.snap
  • packages/components/test/components/__snapshots__/SendOperations.test.js.snap is excluded by !**/*.snap
  • packages/components/test/components/__snapshots__/Usage.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/python/test/components/__snapshots__/Constructor.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/python/test/components/__snapshots__/InitSignature.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/python/test/components/__snapshots__/Send.test.js.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/test/integration-test/__snapshots__/integration.test.js.javascript.snap is excluded by !**/*.snap
  • packages/templates/clients/websocket/test/integration-test/__snapshots__/integration.test.js.python.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • .changeset/fix-ws-swallowed-send-errors.md
  • AGENTS.md
  • packages/components/src/components/SendOperations.js
  • packages/components/src/components/readme/Usage.js
  • packages/templates/clients/websocket/javascript/components/Constructor.js
  • packages/templates/clients/websocket/python/components/Constructor.js
  • packages/templates/clients/websocket/python/components/InitSignature.js
  • packages/templates/clients/websocket/python/components/Send.js

Adi-204
Adi-204 previously approved these changes Jun 5, 2026
@Adi-204

Adi-204 commented Jun 5, 2026

Copy link
Copy Markdown
Member

@derberg lgtm but you need to resolve conflicts

# Conflicts:
#	packages/components/src/components/SendOperations.js
#	packages/components/test/components/__snapshots__/SendOperations.test.js.snap
#	packages/templates/clients/websocket/test/integration-test/__snapshots__/integration.test.js.javascript.snap
@sonarqubecloud

Copy link
Copy Markdown

@Adi-204

Adi-204 commented Jun 12, 2026

Copy link
Copy Markdown
Member

/rtm

@Adi-204

Adi-204 commented Jun 12, 2026

Copy link
Copy Markdown
Member

@derberg can't merge it becoz of changes outside packages folder.

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.

[BUG] Python Template - Errors are swallowed while sending messages

3 participants