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 d51cd89
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internal/pkg/lib/time.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lib

import (
"errors"
"fmt"
"math"
"os"
Expand All @@ -16,9 +17,12 @@ 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 errors.New(
fmt.Sprintf("mlr: 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 d51cd89

Please sign in to comment.