Better error message on unparseable TZ environment variable (#1249)

This commit is contained in:
John Kerl 2023-03-30 08:37:33 -04:00 committed by GitHub
parent dc14420f82
commit 2d00b44ead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 4 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -0,0 +1 @@
mlr --tz .../... -n put -f test/input/sec2localtime-tz.mlr

View file

@ -0,0 +1 @@
mlr: TZ environment variable appears malformed: ".../..."

View file

@ -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"