-
Notifications
You must be signed in to change notification settings - Fork 2.1k
mismatched type with unset bool flags #10476
Copy link
Copy link
Closed
Labels
A:error-unhelpfulThe error message you observe is not helpful to identify the problemThe error message you observe is not helpful to identify the problem
Milestone
Description
related to #10456 (comment)
cc/ @WindSoilder
Describe the bug
with #10456, boolean switches can only be defined with --switch, on the other hand, things like --option: bool and --option: bool = false will behave as any other type and require the outside caller to give an explicite value.
i think this is a good consistency-related improvement, however i found one unhelpful error that might need to be improved to avoid people getting too confused when doing the transition and the upgrade 😋
How to reproduce
- run
def foo [-x: bool] { if not $x { print "ok" }}; foo- see the unhelpful error
Error: nu::shell::type_mismatch
× Type mismatch.
╭─[entry #7:1:1]
1 │ def foo [-x: bool] { if not $x { print "ok" }}; foo
· ─┬
· ╰── bool
╰────Expected behavior
i expected something more like the following more helpful errors,
> def foo [-x: bool] { $x | describe }; foo -x
Error: nu::parser::missing_flag_param
× Missing flag argument.
╭─[entry #5:1:1]
1 │ def foo [-x: bool] { $x | describe }; foo -x
· ─┬
· ╰── flag missing bool argument
╰────> def foo [-x: bool] { if not $x { print "ok" }}; foo -x "foo"
Error: nu::parser::parse_mismatch
× Parse mismatch during operation.
╭─[entry #8:1:1]
1 │ def foo [-x: bool] { if not $x { print "ok" }}; foo -x "foo"
· ──┬──
· ╰── expected bool
╰────what about something like that?
> def foo [-x: bool] { if not $x { print "ok" }}; foo
Error: nu::parser::parse_mismatch
× Parse mismatch during operation.
╭─[entry #8:1:1]
1 │ def foo [-x: bool] { if not $x { print "ok" }}; foo
· ─┬
· ╰── expected bool, found nothing
╰────Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.85.1 |
| branch | main |
| commit_hash | d2c87ad |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.70.0 (90c541806 2023-05-31) |
| rust_channel | 1.70.0-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.70.0 (ec8a8a0ca 2023-04-25) |
| build_time | 2023-09-23 10:22:06 +02:00 |
| build_rust_channel | release |
| allocator | mimalloc |
| features | default, sqlite, trash, which, zip |
| installed_plugins | gstat, nu_plugin_explore |
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A:error-unhelpfulThe error message you observe is not helpful to identify the problemThe error message you observe is not helpful to identify the problem