Skip to content

Commit

Permalink
Return error when casting empty string to duration
Browse files Browse the repository at this point in the history
Closes #4962
  • Loading branch information
mattnibs committed Jan 4, 2024
1 parent 98d319d commit 2870013
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/nano/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var scale = map[string]Duration{

func ParseDuration(s string) (Duration, error) {
if len(s) == 0 {
return 0, nil
return 0, fmt.Errorf("invalid duration: %q", s)
}
var negative bool
if s[0] == '-' {
Expand Down
6 changes: 6 additions & 0 deletions runtime/expr/ztests/cast-dur-empty-string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zed: 'yield duration(this)'

input: '""'

output: |
error({message:"cannot cast to duration",on:""})

0 comments on commit 2870013

Please sign in to comment.