Fix encode/decode todo's (#13683)

Mistakes have been made. I forgot about a bunch of `todo`s in the helper
functions. So, this PR replaces them with proper errors. It also adds
tests for parse-time evaluation, because one `todo` I missed was in a
`run_const` function.
This commit is contained in:
Andrej Kolčin
2024-08-24 17:02:02 +03:00
committed by GitHub
parent 525eac1afd
commit 3f332bef35
7 changed files with 76 additions and 65 deletions

View File

@ -53,7 +53,7 @@ impl Command for DecodeHex {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
todo!()
super::decode(data_encoding::HEXLOWER_PERMISSIVE, call.span(), input)
}
}

View File

@ -54,14 +54,17 @@ fn get_string(input: PipelineData, call_span: Span) -> Result<(String, Span), Sh
match val {
Value::String { val, .. } => Ok((val, span)),
_ => {
todo!("Invalid type")
}
value => Err(ShellError::TypeMismatch {
err_message: "binary or string".to_owned(),
span: call_span,
}),
}
}
PipelineData::ListStream(..) => {
todo!()
}
PipelineData::ListStream(list, ..) => Err(ShellError::PipelineMismatch {
exp_input_type: "binary or string".to_owned(),
dst_span: call_span,
src_span: list.span(),
}),
PipelineData::ByteStream(stream, ..) => {
let span = stream.span();
Ok((stream.into_string()?, span))
@ -80,20 +83,23 @@ fn get_binary(input: PipelineData, call_span: Span) -> Result<(Vec<u8>, Span), S
Value::Binary { val, .. } => Ok((val, span)),
Value::String { val, .. } => Ok((val.into_bytes(), span)),
_ => {
todo!("Invalid type")
}
value => Err(ShellError::TypeMismatch {
err_message: "binary or string".to_owned(),
span: call_span,
}),
}
}
PipelineData::ListStream(..) => {
todo!()
}
PipelineData::ListStream(list, ..) => Err(ShellError::PipelineMismatch {
exp_input_type: "binary or string".to_owned(),
dst_span: call_span,
src_span: list.span(),
}),
PipelineData::ByteStream(stream, ..) => {
let span = stream.span();
Ok((stream.into_bytes()?, span))
}
PipelineData::Empty => {
todo!("Can't have empty data");
}
PipelineData::Empty => Err(ShellError::PipelineEmpty {
dst_span: call_span,
}),
}
}