mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 22:59:52 +02:00
Remove serde derive for ShellError
, replace via LabeledError
(#12319)
# Description This changes the interface for plugins to always represent errors as `LabeledError`s. This is good for altlang plugins, as it would suck for them to have to implement and track `ShellError`. We save a lot of generated code from the `ShellError` serde impl too, so `nu` and plugins get to have a smaller binary size. Reduces the release binary size by 1.2 MiB on my build configuration. # User-Facing Changes - Changes plugin protocol. `ShellError` no longer serialized. - `ShellError` serialize output is different - `ShellError` no longer deserializes to exactly the same value as serialized # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting - [ ] Document in plugin protocol reference
This commit is contained in:
@@ -236,7 +236,7 @@ impl From<StreamMessage> for PluginInput {
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum StreamData {
|
||||
List(Value),
|
||||
Raw(Result<Vec<u8>, ShellError>),
|
||||
Raw(Result<Vec<u8>, LabeledError>),
|
||||
}
|
||||
|
||||
impl From<Value> for StreamData {
|
||||
@@ -245,9 +245,15 @@ impl From<Value> for StreamData {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Result<Vec<u8>, LabeledError>> for StreamData {
|
||||
fn from(value: Result<Vec<u8>, LabeledError>) -> Self {
|
||||
StreamData::Raw(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Result<Vec<u8>, ShellError>> for StreamData {
|
||||
fn from(value: Result<Vec<u8>, ShellError>) -> Self {
|
||||
StreamData::Raw(value)
|
||||
value.map_err(LabeledError::from).into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,10 +270,10 @@ impl TryFrom<StreamData> for Value {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<StreamData> for Result<Vec<u8>, ShellError> {
|
||||
impl TryFrom<StreamData> for Result<Vec<u8>, LabeledError> {
|
||||
type Error = ShellError;
|
||||
|
||||
fn try_from(data: StreamData) -> Result<Result<Vec<u8>, ShellError>, ShellError> {
|
||||
fn try_from(data: StreamData) -> Result<Result<Vec<u8>, LabeledError>, ShellError> {
|
||||
match data {
|
||||
StreamData::Raw(value) => Ok(value),
|
||||
StreamData::List(_) => Err(ShellError::PluginFailedToDecode {
|
||||
@@ -277,6 +283,14 @@ impl TryFrom<StreamData> for Result<Vec<u8>, ShellError> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<StreamData> for Result<Vec<u8>, ShellError> {
|
||||
type Error = ShellError;
|
||||
|
||||
fn try_from(value: StreamData) -> Result<Result<Vec<u8>, ShellError>, ShellError> {
|
||||
Result::<Vec<u8>, LabeledError>::try_from(value).map(|res| res.map_err(ShellError::from))
|
||||
}
|
||||
}
|
||||
|
||||
/// A stream control or data message.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum StreamMessage {
|
||||
|
Reference in New Issue
Block a user