Skip to content

Commit 04dd333

Browse files
committed
Quote some values in error messages
This helps to understand the errors about invalid arguments when the argument's value is the empty string. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
1 parent 6295a73 commit 04dd333

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Changed
6+
7+
- Quote some values in error messages (#24)
8+
39
## 0.8.4
410

511
### Changed

src/climate/error.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,20 @@ module Parse_error = struct
9393
| None -> sprintf "Failed to parse the argument: %s" message)
9494
| Too_many_positional_arguments { max = 0; first_excess_argument } ->
9595
sprintf
96-
"This command does not accept any positional arguments. First excess argument: %s"
96+
"This command does not accept any positional arguments. First excess argument: %S"
9797
first_excess_argument
9898
| Too_many_positional_arguments { max; first_excess_argument } ->
9999
sprintf
100100
"Too many positional arguments. At most %d positional arguments may be passed. \
101-
First excess argument: %s"
101+
First excess argument: %S"
102102
max
103103
first_excess_argument
104104
| Invalid_char_in_argument_name { attempted_argument_name; invalid_char } ->
105105
sprintf
106106
"Invalid character %C in argument name %S"
107107
invalid_char
108108
attempted_argument_name
109-
| No_such_subcommand subcommand -> sprintf "No such subcommand: %s" subcommand
109+
| No_such_subcommand subcommand -> sprintf "No such subcommand: %S" subcommand
110110
;;
111111

112112
let exit_code = 124

tests/unit_tests/parse_error_tests.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ let%expect_test "positional args passed to command with no positional args" =
1212
{| This command does not accept any positional arguments. First excess argument: foo |}]
1313
;;
1414

15+
let%expect_test "empty string passed to command with no positional args" =
16+
run (Command.singleton (Arg_parser.const ())) [ "" ];
17+
[%expect
18+
{| This command does not accept any positional arguments. First excess argument: foo |}]
19+
;;
20+
1521
let%expect_test "positional args passed to command with no positional args" =
1622
let term = Arg_parser.(pos_req 0 string) in
1723
run (Command.singleton term) [ "foo"; "bar"; "baz" ];

0 commit comments

Comments
 (0)