Skip to content

Document and critically review ShellError variants - Ep. 2#8326

Merged
sholderbach merged 8 commits intonushell:mainfrom
sholderbach:errare-humanum-est
Mar 6, 2023
Merged

Document and critically review ShellError variants - Ep. 2#8326
sholderbach merged 8 commits intonushell:mainfrom
sholderbach:errare-humanum-est

Conversation

@sholderbach
Copy link
Copy Markdown
Member

@sholderbach sholderbach commented Mar 5, 2023

Continuation of #8229

Description

The ShellError enum at the moment is kind of messy.

Many variants are basic tuple structs where you always have to reference the implementation with its macro invocation to know which field serves which purpose.
Furthermore we have both variants that are kind of redundant or either overly broad to be useful for the user to match on or overly specific with few uses.

So I set out to start fixing the lacking documentation and naming to make it feasible to critically review the individual usages and fix those.
Furthermore we can decide to join or split up variants that don't seem to be fit for purpose.

Everyone: Feel free to add review comments if you spot inconsistent use of ShellError variants.

  • Name fields of SE::IncorrectValue
  • Merge and name fields on SE::TypeMismatch
  • Name fields on SE::UnsupportedOperator
  • Name fields on AssignmentRequires* and fix doc
  • Name fields on SE::UnknownOperator
  • Name fields on SE::MissingParameter
  • Name fields on SE::DelimiterError
  • Name fields on SE::IncompatibleParametersSingle

User-Facing Changes

(None now, end goal more explicit and consistent error messages)

Tests + Formatting

(No additional tests needed so far)

TODO: move things that probably use another error variant either to
this or remove the `IncorrectValue` entirely.
Incorporates the once used `TypeMismatchGenericMessage`

Still need to figure out what the hell happened that we have a highly
messy `TypeMismatch` that regularly seems to concern it self with other
things than type errors in the narrow sense.
Observed one case of flagrant misuse of it
We are a bit inconsistent if we provide a long message or the ostensible
parameter name based on the signature. We insert this string both in the
head message and the tagged label. Here a long string might be confusing
@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented Mar 5, 2023

Nice, thanks! I skimmed the changes to shell_error.rs, looks good.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2023

Codecov Report

Merging #8326 (1b6de1b) into main (c1d76bf) will decrease coverage by 0.03%.
The diff coverage is 26.80%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8326      +/-   ##
==========================================
- Coverage   68.19%   68.16%   -0.03%     
==========================================
  Files         620      620              
  Lines       99288    99343      +55     
==========================================
+ Hits        67705    67719      +14     
- Misses      31583    31624      +41     
Impacted Files Coverage Δ
crates/nu-command/src/bytes/at.rs 70.94% <0.00%> (ø)
crates/nu-command/src/bytes/build_.rs 89.28% <0.00%> (ø)
crates/nu-command/src/bytes/remove.rs 89.82% <0.00%> (ø)
crates/nu-command/src/bytes/replace.rs 91.09% <0.00%> (ø)
crates/nu-command/src/charting/histogram.rs 88.60% <0.00%> (-0.76%) ⬇️
crates/nu-command/src/conversions/into/datetime.rs 84.48% <0.00%> (ø)
crates/nu-command/src/conversions/into/int.rs 75.75% <0.00%> (ø)
crates/nu-command/src/conversions/into/string.rs 79.43% <0.00%> (ø)
crates/nu-command/src/date/to_timezone.rs 87.06% <0.00%> (-2.32%) ⬇️
crates/nu-command/src/filesystem/mkdir.rs 87.95% <0.00%> (ø)
... and 59 more

@sholderbach
Copy link
Copy Markdown
Member Author

Nice, thanks! I skimmed the changes to shell_error.rs, looks good.

The real meat and potatoes for the users is still in all the usages that might use the wrong error type or misunderstood how the fields were intended (or that got more confusing when the format string in the miette macros was updated). But that we can try to get right step by step.

@sholderbach sholderbach merged commit f7b8f97 into nushell:main Mar 6, 2023
@sholderbach sholderbach deleted the errare-humanum-est branch March 6, 2023 10:31
sholderbach added a commit that referenced this pull request Mar 6, 2023
Continuation of #8229 and #8326

# Description

The `ShellError` enum at the moment is kind of messy. 

Many variants are basic tuple structs where you always have to reference
the implementation with its macro invocation to know which field serves
which purpose.
Furthermore we have both variants that are kind of redundant or either
overly broad to be useful for the user to match on or overly specific
with few uses.

So I set out to start fixing the lacking documentation and naming to
make it feasible to critically review the individual usages and fix
those.
Furthermore we can decide to join or split up variants that don't seem
to be fit for purpose.

# Call to action

**Everyone:** Feel free to add review comments if you spot inconsistent
use of `ShellError` variants.

# User-Facing Changes

(None now, end goal more explicit and consistent error messages)

# Tests + Formatting

(No additional tests needed so far)

# Commits (so far)

- Remove `ShellError::FeatureNotEnabled`
- Name fields on `SE::ExternalNotSupported`
- Name field on `SE::InvalidProbability`
- Name fields on `SE::NushellFailed` variants
- Remove unused `SE::NushellFailedSpannedHelp`
- Name field on `SE::VariableNotFoundAtRuntime`
- Name fields on `SE::EnvVarNotFoundAtRuntime`
- Name fields on `SE::ModuleNotFoundAtRuntime`
- Remove usused `ModuleOrOverlayNotFoundAtRuntime`
- Name fields on `SE::OverlayNotFoundAtRuntime`
- Name field on `SE::NotFound`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants