Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message on unparseable TZ environment variable #1249

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
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"