Convert ShellError::UnsupportedInput to named fields (#10971)

# Description

This is easy to do with rust-analyzer, but I didn't want to just pump
these all out without feedback.

Part of #10700

# User-Facing Changes

None

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

N/A

---------

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Eric Hodel
2023-11-07 14:25:32 -08:00
committed by GitHub
parent 45b02ce2ab
commit 7a3cbf43e8
56 changed files with 506 additions and 567 deletions

View File

@ -56,13 +56,8 @@ pub fn http_parse_url(
let url = match url::Url::parse(&requested_url) {
Ok(u) => u,
Err(_e) => {
return Err(ShellError::UnsupportedInput(
"Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
.to_string(),
format!("value: '{requested_url:?}'"),
call.head,
span,
));
return Err(ShellError::UnsupportedInput { msg: "Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
.to_string(), input: format!("value: '{requested_url:?}'"), msg_span: call.head, input_span: span });
}
};

View File

@ -75,12 +75,12 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
row_vec.push((k.clone(), s.to_string()));
}
_ => {
return Err(ShellError::UnsupportedInput(
"Expected a record with string values".to_string(),
"value originates from here".into(),
head,
span,
));
return Err(ShellError::UnsupportedInput {
msg: "Expected a record with string values".to_string(),
input: "value originates from here".into(),
msg_span: head,
input_span: span,
});
}
}
}
@ -97,12 +97,12 @@ fn to_url(input: PipelineData, head: Span) -> Result<PipelineData, ShellError> {
}
// Propagate existing errors
Value::Error { error, .. } => Err(*error),
other => Err(ShellError::UnsupportedInput(
"Expected a table from pipeline".to_string(),
"value originates from here".into(),
head,
other.span(),
)),
other => Err(ShellError::UnsupportedInput {
msg: "Expected a table from pipeline".to_string(),
input: "value originates from here".into(),
msg_span: head,
input_span: other.span(),
}),
}
})
.collect();

View File

@ -104,12 +104,12 @@ impl Command for SubCommand {
url_components?.to_url(span)
}
Value::Error { error, .. } => Err(*error),
other => Err(ShellError::UnsupportedInput(
"Expected a record from pipeline".to_string(),
"value originates from here".into(),
head,
other.span(),
)),
other => Err(ShellError::UnsupportedInput {
msg: "Expected a record from pipeline".to_string(),
input: "value originates from here".into(),
msg_span: head,
input_span: other.span(),
}),
}
})
.collect();

View File

@ -113,21 +113,21 @@ fn parse(value: Value, head: Span, engine_state: &EngineState) -> Result<Pipelin
Ok(PipelineData::Value(Value::record(record, head), None))
}
_ => Err(ShellError::UnsupportedInput(
"String not compatible with url-encoding".to_string(),
"value originates from here".into(),
head,
span,
)),
_ => Err(ShellError::UnsupportedInput {
msg: "String not compatible with url-encoding".to_string(),
input: "value originates from here".into(),
msg_span: head,
input_span: span,
}),
}
}
Err(_e) => Err(ShellError::UnsupportedInput(
"Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
Err(_e) => Err(ShellError::UnsupportedInput {
msg: "Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
.to_string(),
"value originates from here".into(),
head,
span,
)),
input: "value originates from here".into(),
msg_span: head,
input_span: span,
}),
}
}