Skip to content

Commit

Permalink
Add additional span to IncorrectValue error (#10036)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubouch committed Aug 18, 2023
1 parent cdf09ab commit fb908df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion crates/nu-cmd-dataframe/src/dataframe/eager/to_avro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ fn get_compression(call: &Call) -> Result<Option<AvroCompression>, ShellError> {
"deflate" => Ok(Some(AvroCompression::Deflate)),
_ => Err(ShellError::IncorrectValue {
msg: "compression must be one of deflate or snappy".to_string(),
span,
val_span: span,
call_span: span,
}),
}
} else {
Expand Down
8 changes: 6 additions & 2 deletions crates/nu-command/src/conversions/into/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
Value::Int { val: 0, span }
}
}
Value::Date { val, .. } => {
Value::Date {
val,
span: val_span,
} => {
if val
< &FixedOffset::east_opt(0)
.expect("constant")
Expand All @@ -267,7 +270,8 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
Value::Error {
error: Box::new(ShellError::IncorrectValue {
msg: "DateTime out of range for timestamp: 1677-09-21T00:12:43Z to 2262-04-11T23:47:16".to_string(),
span
val_span: *val_span,
call_span: span,
}),
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion crates/nu-command/src/strings/str_/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ fn action(
Err(e) => Value::Error {
error: Box::new(ShellError::IncorrectValue {
msg: format!("Regex error: {e}"),
span: find.span,
val_span: find.span,
call_span: head,
}),
},
}
Expand Down
4 changes: 3 additions & 1 deletion crates/nu-protocol/src/shell_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ pub enum ShellError {
IncorrectValue {
msg: String,
#[label = "{msg}"]
span: Span,
val_span: Span,
#[label = "encountered here"]
call_span: Span,
},

/// This value cannot be used with this operator.
Expand Down

0 comments on commit fb908df

Please sign in to comment.