Skip to content

Commit

Permalink
Better error message on unparseable TZ environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Mar 30, 2023
1 parent 5f9ac90 commit 596f119
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/entrypoint/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Main() MainReturn {

options, recordTransformers, err := climain.ParseCommandLine(os.Args)
if err != nil {
fmt.Fprintln(os.Stderr, os.Args[0], ": ", err)
fmt.Fprintln(os.Stderr, "mlr:", err)
os.Exit(1)
}

Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/lib/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
// platform this is necessary for *changing* TZ mid-process: e.g. if a DSL
// statement does 'ENV["TZ"] = Asia/Istanbul'.
func SetTZFromEnv() error {
location, err := time.LoadLocation(os.Getenv("TZ"))
tzenv := os.Getenv("TZ")
location, err := time.LoadLocation(tzenv)
if err != nil {
return err
return fmt.Errorf("TZ environment variable appears malformed: \"%s\"", tzenv)
}
time.Local = location
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --tz .../... -n put -f test/input/sec2localtime-tz.mlr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: TZ environment variable appears malformed: ".../..."
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${MLR} : unknown time zone this-is-not-a-valid-timezone-name
mlr: TZ environment variable appears malformed: "this-is-not-a-valid-timezone-name"

0 comments on commit 596f119

Please sign in to comment.