use abbreviated string instead of debug string for DatetimeParseErrors (#12517)

Resolves #12444. Prevents debug string from being printed out.

---------

Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
pwygab 2024-04-17 05:19:03 +08:00 committed by GitHub
parent cc781a1ecd
commit 43814dcb0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 32 additions and 20 deletions

View file

@ -332,7 +332,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
}
None => Value::error(
ShellError::DatetimeParseError {
msg: input.to_debug_string(),
msg: input.to_abbreviated_string(&nu_protocol::Config::default()),
span: *span,
},
*span,
@ -345,7 +345,7 @@ fn action(input: &Value, args: &Arguments, head: Span) -> Value {
}
None => Value::error(
ShellError::DatetimeParseError {
msg: input.to_debug_string(),
msg: input.to_abbreviated_string(&nu_protocol::Config::default()),
span: *span,
},
*span,

View file

@ -78,9 +78,11 @@ fn helper(value: Value, head: Span) -> Value {
}
Value::Date { val, .. } => Value::string(humanize_date(val), head),
_ => Value::error(
ShellError::DatetimeParseError {
msg: value.to_debug_string(),
span: head,
ShellError::OnlySupportsThisInputType {
exp_input_type: "date, string (that represents datetime), or nothing".into(),
wrong_type: value.get_type().to_string(),
dst_span: head,
src_span: span,
},
head,
),

View file

@ -112,9 +112,11 @@ fn helper(val: Value, head: Span) -> Value {
}
Value::Date { val, .. } => parse_date_into_table(val, head),
_ => Value::error(
ShellError::DatetimeParseError {
msg: val.to_debug_string(),
span: head,
ShellError::OnlySupportsThisInputType {
exp_input_type: "date, string (that represents datetime), or nothing".into(),
wrong_type: val.get_type().to_string(),
dst_span: head,
src_span: span,
},
head,
),

View file

@ -111,9 +111,11 @@ fn helper(val: Value, head: Span) -> Value {
}
Value::Date { val, .. } => parse_date_into_table(val, head),
_ => Value::error(
ShellError::DatetimeParseError {
msg: val.to_debug_string(),
span: head,
ShellError::OnlySupportsThisInputType {
exp_input_type: "date, string (that represents datetime), or nothing".into(),
wrong_type: val.get_type().to_string(),
dst_span: head,
src_span: val_span,
},
head,
),

View file

@ -115,9 +115,11 @@ fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
_to_timezone(dt.with_timezone(dt.offset()), timezone, head)
}
_ => Value::error(
ShellError::DatetimeParseError {
msg: value.to_debug_string(),
span: head,
ShellError::OnlySupportsThisInputType {
exp_input_type: "date, string (that represents datetime), or nothing".into(),
wrong_type: value.get_type().to_string(),
dst_span: head,
src_span: val_span,
},
head,
),

View file

@ -153,9 +153,11 @@ fn format_helper(value: Value, formatter: &str, formatter_span: Span, head_span:
}
}
_ => Value::error(
ShellError::DatetimeParseError {
msg: value.to_debug_string(),
span: head_span,
ShellError::OnlySupportsThisInputType {
exp_input_type: "date, string (that represents datetime)".into(),
wrong_type: value.get_type().to_string(),
dst_span: head_span,
src_span: value.span(),
},
head_span,
),
@ -174,9 +176,11 @@ fn format_helper_rfc2822(value: Value, span: Span) -> Value {
}
}
_ => Value::error(
ShellError::DatetimeParseError {
msg: value.to_debug_string(),
span,
ShellError::OnlySupportsThisInputType {
exp_input_type: "date, string (that represents datetime)".into(),
wrong_type: value.get_type().to_string(),
dst_span: span,
src_span: val_span,
},
span,
),