Skip to content

Comments

fix(linter/plugins): handle errors sending data from JS back to Rust#16463

Closed
overlookmotel wants to merge 1 commit into12-03-docs_linter_plugins_improve_comment_on_error_branchfrom
12-03-fix_linter_plugins_handle_errors_sending_data_from_js_back_to_rust
Closed

fix(linter/plugins): handle errors sending data from JS back to Rust#16463
overlookmotel wants to merge 1 commit into12-03-docs_linter_plugins_improve_comment_on_error_branchfrom
12-03-fix_linter_plugins_handle_errors_sending_data_from_js_back_to_rust

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Dec 3, 2025

Previously if there was an error passing data back from a ThreadsafeFunction callback into Rust calling thread using the mpsc::channel, we'd just ignore it. Presumably then the later call to rx.recv() would just hang forever waiting for a message.

I'm not that familiar with mpsc::channel, but from the docs it looks like this is impossible in these functions, because we definitely don't drop the receiver before the tx.send() call happens - because we block on rx.recv().

But nonetheless, it seems wise to handle this, just in case there's a bug in NAPI-RS or something.

If tx.send() fails, return a napi::Error from the callback. This causes the error to be thrown on JS side, where it's unhandled and so will crash the NodeJS process. But this is probably what we want to happen, as there's no way to gracefully recover.

(it's not documented what behavior is if you return Err from the callback, but I've tried it out, and this is what happens)

Copy link
Member Author

overlookmotel commented Dec 3, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves error handling in the JavaScript plugin integration by properly handling mpsc::channel send errors. Previously, these errors were silently ignored with let _ = tx.send(result). The changes replace this with proper error propagation using .map_err() that returns a NapiError, which will cause the NodeJS process to crash with an unhandled error - appropriate for these theoretically impossible but catastrophic failure cases.

  • Replaces silent error ignoring with proper error handling in ThreadsafeFunction callbacks
  • Adds descriptive error messages for send failures in both setupConfigs and lintFile functions
  • Imports NapiError from the napi crate to enable error construction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel force-pushed the 12-03-fix_linter_plugins_handle_errors_sending_data_from_js_back_to_rust branch from a148597 to 71baec9 Compare December 3, 2025 18:19
@overlookmotel overlookmotel self-assigned this Dec 3, 2025
@overlookmotel overlookmotel force-pushed the 12-03-fix_linter_plugins_handle_errors_sending_data_from_js_back_to_rust branch 2 times, most recently from e958074 to 4bdc499 Compare December 3, 2025 18:34
@overlookmotel overlookmotel changed the base branch from 12-03-refactor_linter_plugins_simplify_return_value_of_load_plugin_ to graphite-base/16463 December 3, 2025 18:43
@overlookmotel overlookmotel force-pushed the 12-03-fix_linter_plugins_handle_errors_sending_data_from_js_back_to_rust branch from 4bdc499 to 3da3238 Compare December 3, 2025 18:43
@overlookmotel overlookmotel changed the base branch from graphite-base/16463 to 12-03-docs_linter_plugins_improve_comment_on_error_branch December 3, 2025 18:43
@overlookmotel
Copy link
Member Author

Closing in favour of #16465.

@overlookmotel overlookmotel deleted the 12-03-fix_linter_plugins_handle_errors_sending_data_from_js_back_to_rust branch December 3, 2025 19:02
graphite-app bot pushed a commit that referenced this pull request Dec 3, 2025
… callback (#16465)

Alternative to #16463.

I think I've understood the situation now, and why Brooooklyn's original code ignored the result of `tx.send()`.

It is genuinely impossible for the call to `tx.send()` to fail, and that doesn't depend on there not being a bug in NAPI-RS - it's provable just from looking at the code in these functions, regardless of what NAPI-RS may do.

Add comments explaining why we can safely ignore the result of `tx.send()`, and add a `debug_assert!` just to make sure.

We want to absolutely minimize the overhead of moving between JS and Rust, so I think it's appropriate to leave out error handling for impossible cases like these.
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
… callback (oxc-project#16465)

Alternative to oxc-project#16463.

I think I've understood the situation now, and why Brooooklyn's original code ignored the result of `tx.send()`.

It is genuinely impossible for the call to `tx.send()` to fail, and that doesn't depend on there not being a bug in NAPI-RS - it's provable just from looking at the code in these functions, regardless of what NAPI-RS may do.

Add comments explaining why we can safely ignore the result of `tx.send()`, and add a `debug_assert!` just to make sure.

We want to absolutely minimize the overhead of moving between JS and Rust, so I think it's appropriate to leave out error handling for impossible cases like these.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants