nushell/crates/nu-plugin/src
Devyn Cairns 48e4448e55
Add a panic unwind handler during plugin calls (#12526)
# Description
If a panic happens during a plugin call, because it always happens
outside of the main thread, it currently just hangs Nushell because the
plugin stays running without ever producing a response to the call.

This adds a panic handler that calls `exit(1)` after the unwind finishes
to the plugin runner. The panic error is still printed to stderr as
always, and waiting for the unwind to finish helps to ensure that
anything on the stack with `Drop` behavior that needed to run still
runs, at least on that thread.

# User-Facing Changes
Panics now look like this, which is what they looked like before the
plugin behavior was moved to a separate thread:

```
thread 'plugin runner (primary)' panicked at crates/nu_plugin_example/src/commands/main.rs:45:9:
Test panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: nu:🐚:plugin_failed_to_decode

  × Plugin failed to decode: Failed to receive response to plugin call

```

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
2024-04-16 15:00:32 +00:00
..
plugin Add a panic unwind handler during plugin calls (#12526) 2024-04-16 15:00:32 +00:00
protocol Local socket mode and foreground terminal control for plugins (#12448) 2024-04-15 18:28:18 +00:00
serializers Improve error messages for plugin protocol by removing #[serde(untagged)] (#12510) 2024-04-14 15:55:18 +00:00
util Local socket mode and foreground terminal control for plugins (#12448) 2024-04-15 18:28:18 +00:00
lib.rs Make drop notification timing for plugin custom values more consistent (#12341) 2024-04-04 09:13:25 +02:00
sequence.rs Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00