Repository navigation
give better error if required field of url join is invalid - #10589
Conversation
|
@sholderbach from #10506
No, but this should. |
|
Will look into the details tomorrow but in general we don't treat the empty string as null. |
|
Yeah probably shouldn't group it in with null. I could change it to say something like: That will have to be tomorrow though. |
|
i agree with @sholderbach that the first error would be less confusing if it were to say ➜ {scheme: "", host: "github.com"} | url join
Error: nu::shell::unexpected_argument
× Expected non-empty string.
╭─[entry #16:1:1]
1 │ {scheme: "", host: "github.com"} | url join
· ─┬
· ╰── expected non-empty string
╰────maybe creating another error type just for this is not the right way to go 🤔 the second error looks very nice 👌 |
|
Updated examples: ➜ {scheme: "https", host: ""} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #1:1:1]
1 │ {scheme: "https", host: ""} | url join
· ─┬
· ╰── expected non-empty string, got empty string
╰────❯ {scheme: null, host: "github.com"} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #2:1:1]
1 │ {scheme: null, host: "github.com"} | url join
· ──┬─
· ╰── expected non-empty string, got null or empty value
╰────➜ {scheme: [], host: "github.com"} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #1:1:1]
1 │ {scheme: [], host: "github.com"} | url join
· ─┬
· ╰── expected non-empty string, got null or empty value
╰────I went for the
and I didn't want to add much more logic for a simple error. I also removed the new |
|
mm now that we can see it, i'm personally not a huge fan of these... 🤔 if |
|
@amtoine At this point in the Are you saying check all values for being non-empty strings and error on any if they are empty (instead of just on |
|
this might be a bit too far out of scope for this PR and the work you've done 🤔 but what i mean is that, to be as little confusing as possible for the user, i think we should have errors like
❯ {host: "github.com"} | url join
Error: nu::shell::missing_parameter
× Missing parameter: scheme.
╭─[entry #1:1:1]
1 │ {host: "github.com"} | url join
· ──────────┬─────────
· ╰── missing parameter: scheme
╰────
❯ {scheme: null, host: "github.com"} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #2:1:1]
1 │ {scheme: null, host: "github.com"} | url join
· ──┬─
· ╰── expected string, got nothing
╰────➜ {scheme: [], host: "github.com"} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #1:1:1]
1 │ {scheme: [], host: "github.com"} | url join
· ─┬
· ╰── expected string, got list
╰────
➜ {scheme: "https", host: ""} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #1:1:1]
1 │ {scheme: "https", host: ""} | url join
· ─┬
· ╰── expected non-empty string
╰──── |
|
@amtoine I looked into it and this would require some matching of the value after checking if it can be converted to a string using ❯ {scheme: hello, host: null} | url join
Error: nu::shell::cant_convert
× Can't convert to string.
╭─[entry #3:1:1]
1 │ {scheme: hello, host: null} | url join
· ──┬─
· ╰── can't convert nothing to string
╰────❯ {scheme: hello, host: []} | url join
Error: nu::shell::cant_convert
× Can't convert to string.
╭─[entry #5:1:1]
1 │ {scheme: hello, host: []} | url join
· ─┬
· ╰── can't convert list<any> to string
╰────Also: The other messages for missing required values and empty strings would look like what you suggested. |
|
i think this looks quite good, because you'd see what the actual and expected types are 👌 let's go with this, if you have time to make the change, that'd be amazing 🙏 if the wording is not perfect in the end, this can be addressed in a follow-up PR 😉 |
…ng()` error if it fails
|
@amtoine Ok... I hope this commit finalizes this PR. The updated error messages are as follows:
➜ {scheme: hello, host: []} | url join
Error: nu::shell::cant_convert
× Can't convert to string.
╭─[entry #2:1:1]
1 │ {scheme: hello, host: []} | url join
· ─┬
· ╰── can't convert list<any> to string
╰────
❯ {scheme: hello, host: ""} | url join
Error: nu::shell::unsupported_config_value
× Unsupported config value
╭─[entry #3:1:1]
1 │ {scheme: hello, host: ""} | url join
· ─┬
· ╰── expected non-empty string, got empty string
╰────
❯ {scheme: hello} | url join
Error: nu::shell::missing_parameter
× Missing parameter: host.
╭─[entry #4:1:1]
1 │ {scheme: hello} | url join
· ───────┬───────
· ╰── missing parameter: host
╰──── |
|
@brunerm99 |
|
Hey @amtoine, I fixed the problem but it looks like the CI failed due to a network error. Snip from failed test: Could this CI be re-run? Looks unrelated to my code, I think. |
|
@amtoine CI is now passing. Thanks @sholderbach for restarting it. |
|
oh yeah i got the exact same failure in #10341 😮 |
|
let's land this PR, it looks much better than before 🙏 |
ExpectedNonNull ShellError if required field is entered as $nothing, null, "", etc.url join is invalid
same because it was so unrelated to the changes 😆
anytime 😊 |
…#10589) # Description Fix nushell#10506 by adding `ExpectedNonNull` `ShellError` if required field is entered as `$nothing`, `null`, " ", etc. This adds a new `ShellError`, `ExpectedNonNull`, taking the expected type and span. # User-Facing Changes Will get a more helpful error in the case described by nushell#10506. Examples: ```nushell ➜ {scheme: "", host: "github.com"} | url join Error: nu::shell::expected_non_null × Expected string found null. ╭─[entry nushell#16:1:1] 1 │ {scheme: "", host: "github.com"} | url join · ─┬ · ╰── expected string, found null ╰──── ``` ```nushell ❯ {scheme: "https", host: null} | url join Error: nu:🐚:expected_non_null × Expected string found null. ╭─[entry nushell#19:1:1] 1 │ {scheme: "https", host: null} | url join · ──┬─ · ╰── expected string, found null ╰──── ``` # Tests + Formatting All pass.
Description
Fix #10506 by adding
ExpectedNonNullShellErrorif required field isentered as
$nothing,null, " ", etc.This adds a new
ShellError,ExpectedNonNull, taking the expectedtype and span.
User-Facing Changes
Will get a more helpful error in the case described by #10506. Examples:
Tests + Formatting
All pass.