From 43814dcb0fa24f29a65ccf680126cc8cd811e372 Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Wed, 17 Apr 2024 05:19:03 +0800 Subject: [PATCH] use abbreviated string instead of debug string for `DatetimeParseError`s (#12517) Resolves #12444. Prevents debug string from being printed out. --------- Co-authored-by: sholderbach --- .../nu-command/src/conversions/into/datetime.rs | 4 ++-- crates/nu-command/src/date/humanize.rs | 8 +++++--- crates/nu-command/src/date/to_record.rs | 8 +++++--- crates/nu-command/src/date/to_table.rs | 8 +++++--- crates/nu-command/src/date/to_timezone.rs | 8 +++++--- crates/nu-command/src/strings/format/date.rs | 16 ++++++++++------ 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/crates/nu-command/src/conversions/into/datetime.rs b/crates/nu-command/src/conversions/into/datetime.rs index ff2dca88a5..abb0442229 100644 --- a/crates/nu-command/src/conversions/into/datetime.rs +++ b/crates/nu-command/src/conversions/into/datetime.rs @@ -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, diff --git a/crates/nu-command/src/date/humanize.rs b/crates/nu-command/src/date/humanize.rs index b47288f636..2815571520 100644 --- a/crates/nu-command/src/date/humanize.rs +++ b/crates/nu-command/src/date/humanize.rs @@ -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, ), diff --git a/crates/nu-command/src/date/to_record.rs b/crates/nu-command/src/date/to_record.rs index 9d42e42d90..e22e475aa3 100644 --- a/crates/nu-command/src/date/to_record.rs +++ b/crates/nu-command/src/date/to_record.rs @@ -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, ), diff --git a/crates/nu-command/src/date/to_table.rs b/crates/nu-command/src/date/to_table.rs index 0c0690e09b..5455c21e4b 100644 --- a/crates/nu-command/src/date/to_table.rs +++ b/crates/nu-command/src/date/to_table.rs @@ -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, ), diff --git a/crates/nu-command/src/date/to_timezone.rs b/crates/nu-command/src/date/to_timezone.rs index 2b555c02bf..5f41d287ae 100644 --- a/crates/nu-command/src/date/to_timezone.rs +++ b/crates/nu-command/src/date/to_timezone.rs @@ -115,9 +115,11 @@ fn helper(value: Value, head: Span, timezone: &Spanned) -> 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, ), diff --git a/crates/nu-command/src/strings/format/date.rs b/crates/nu-command/src/strings/format/date.rs index 146822aa65..a85e62c679 100644 --- a/crates/nu-command/src/strings/format/date.rs +++ b/crates/nu-command/src/strings/format/date.rs @@ -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, ),