Commit 58c0974
authored
Fix panic on empty --json flag value (#5498)
## Why
Found during a full-repo review of the CLI. Passing an empty value to
`--json` (for example `databricks jobs create --json=`, or `--json
"$VAR"` where the shell variable is unset) crashed the CLI with an index
out of range panic instead of a usable error message.
## Changes
Before, an empty `--json` value panicked; now it fails with a clean
validation error. `JsonFlag.Set` in `libs/flags/json_flag.go` indexed
`v[0]` to check for the `@file` prefix without first checking the
length. It now rejects empty input up front, and cobra surfaces it as
`invalid argument "" for "--json" flag: expected inline JSON or
@path/to/file, got an empty string`.
## Test plan
- [x] New unit test `TestJsonFlagEmptyValue` covering the empty value
case (panics without the fix, passes with it)
- [x] `go test ./libs/flags` passes
- [x] `./task fmt-q`, `./task lint-q`, and `./task checks` pass
This pull request and its description were written by Isaac.1 parent 2a71127 commit 58c0974
2 files changed
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
| |||
0 commit comments