Skip to content

Commit

Permalink
Fix error message propagation on plugin call failure (nushell#12632)
Browse files Browse the repository at this point in the history
# Description

This should fix the sometimes failing wrong version test for
stress_internals.

The plugin interface state stores an error if some kind of critical
error happened, and this error should be propagated to any future
operations on the interface, but this wasn't being propagated to plugin
calls that were already waiting.

During plugin registration, the wrong version error needs to be received
as a response to the `get_signature()` to show up properly, but this
would only happen if `get_signature()` started after the `Hello` was
already received and processed. That would be a race condition, which
this commit solves.

cc @sholderbach - this should fix the CI issue

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
  • Loading branch information
devyn authored Apr 23, 2024
1 parent eec8645 commit c9bc0c7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/nu-plugin/src/plugin/interface/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,15 @@ impl PluginInterface {
}
}
}
// If we fail to get a response
Err(ShellError::PluginFailedToDecode {
msg: "Failed to receive response to plugin call".into(),
})
// If we fail to get a response, check for an error in the state first, and return it if
// set. This is probably a much more helpful error than 'failed to receive response'
if let Some(error) = self.state.error.get() {
Err(error.clone())
} else {
Err(ShellError::PluginFailedToDecode {
msg: "Failed to receive response to plugin call".into(),
})
}
}

/// Handle an engine call and write the response.
Expand Down

0 comments on commit c9bc0c7

Please sign in to comment.