Skip to content

Commit ab35e4e

Browse files
committed
Decouple error reporting from logging
The Fail callback was routing errors through the slog logger, which meant: - Errors appeared as structured log messages (with timestamp and level) - --log-level never silently swallowed errors - --log-format json wrapped errors in JSON Errors are now always printed directly to stderr as "Error: <message>", independent of log configuration. Default log level changed from "info" to "never"; server start-dev continues to default to "warn" via its existing ChangedFromDefault override. Users can still opt in with --log-level on any command. Two deprecation warnings (namespace arg, env command args) converted from logger calls to direct stderr writes so they remain visible regardless of log level.
1 parent 3624b38 commit ab35e4e

File tree

7 files changed

+9
-13
lines changed

7 files changed

+9
-13
lines changed

cliext/flags.gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func (v *CommonOptions) BuildFlags(f *pflag.FlagSet) {
3838
f.StringVar(&v.Profile, "profile", "", "Profile to use for config file. EXPERIMENTAL.")
3939
f.BoolVar(&v.DisableConfigFile, "disable-config-file", false, "If set, disables loading environment config from config file. EXPERIMENTAL.")
4040
f.BoolVar(&v.DisableConfigEnv, "disable-config-env", false, "If set, disables loading environment config from environment variables. EXPERIMENTAL.")
41-
v.LogLevel = NewFlagStringEnum([]string{"debug", "info", "warn", "error", "never"}, "info")
42-
f.Var(&v.LogLevel, "log-level", "Log level. Default is \"info\" for most commands and \"warn\" for \"server start-dev\". Accepted values: debug, info, warn, error, never.")
41+
v.LogLevel = NewFlagStringEnum([]string{"debug", "info", "warn", "error", "never"}, "never")
42+
f.Var(&v.LogLevel, "log-level", "Log level. Default is \"never\" for most commands and \"warn\" for \"server start-dev\". Accepted values: debug, info, warn, error, never.")
4343
v.LogFormat = NewFlagStringEnum([]string{"text", "json", "pretty"}, "text")
4444
f.Var(&v.LogFormat, "log-format", "Log format. Accepted values: text, json.")
4545
v.Output = NewFlagStringEnum([]string{"text", "json", "jsonl", "none"}, "text")

cliext/option-sets.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ option-sets:
5151
- never
5252
description: |
5353
Log level.
54-
Default is "info" for most commands and "warn" for "server start-dev".
55-
default: info
54+
Default is "never" for most commands and "warn" for "server start-dev".
55+
default: never
5656
- name: log-format
5757
type: string-enum
5858
description: Log format.

internal/temporalcli/commands.env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func (c *TemporalEnvCommand) envNameAndKey(cctx *CommandContext, args []string, keyFlag string) (string, string, error) {
1515
if len(args) > 0 {
16-
cctx.Logger.Warn("Arguments to env commands are deprecated; please use --env and --key (or -k) instead")
16+
fmt.Fprintln(cctx.Options.Stderr, "Warning: Arguments to env commands are deprecated; please use --env and --key (or -k) instead")
1717

1818
if c.Parent.Env != "default" || keyFlag != "" {
1919
return "", "", fmt.Errorf("cannot specify both an argument and flags; please use flags instead")

internal/temporalcli/commands.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ func (c *CommandContext) preprocessOptions() error {
143143
if c.Err() != nil {
144144
err = fmt.Errorf("program interrupted")
145145
}
146-
if c.Logger != nil {
147-
c.Logger.Error(err.Error())
148-
} else {
149-
fmt.Fprintln(os.Stderr, err)
150-
}
146+
fmt.Fprintf(c.Options.Stderr, "Error: %v\n", err)
151147
os.Exit(1)
152148
}
153149
}

internal/temporalcli/commands.operator_namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (c *TemporalOperatorCommand) getNSFromFlagOrArg0(cctx *CommandContext, args
1919
}
2020

2121
if len(args) > 0 {
22-
cctx.Logger.Warn("Passing the namespace as an argument is now deprecated; please switch to using -n instead")
22+
fmt.Fprintln(cctx.Options.Stderr, "Warning: Passing the namespace as an argument is now deprecated; please switch to using -n instead")
2323
return args[0], nil
2424
}
2525
return c.Namespace, nil

internal/temporalcli/commands.workflow_exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (c *TemporalWorkflowExecuteCommand) run(cctx *CommandContext, args []string
9494
// Log print failure and return workflow failure if workflow failed
9595
if closeEvent.EventType != enums.EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED {
9696
if err != nil {
97-
cctx.Logger.Error("Workflow failed, and printing the output also failed", "error", err)
97+
fmt.Fprintf(cctx.Options.Stderr, "Warning: printing workflow output failed: %v\n", err)
9898
}
9999
err = fmt.Errorf("workflow failed")
100100
}

internal/temporalcli/commands.workflow_view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func (c *TemporalWorkflowResultCommand) run(cctx *CommandContext, _ []string) er
560560
// Log print failure and return workflow failure if workflow failed
561561
if closeEvent.EventType != enums.EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED {
562562
if err != nil {
563-
cctx.Logger.Error("Workflow failed, and printing the output also failed", "error", err)
563+
fmt.Fprintf(cctx.Options.Stderr, "Warning: printing workflow output failed: %v\n", err)
564564
}
565565
err = fmt.Errorf("workflow failed")
566566
}

0 commit comments

Comments
 (0)