sipeed/picoclaw · error
failed to set %s: %w
Error message
failed to set %s: %w
What it means
When --host resolves, gateway RunE exports it as the config.EnvGatewayHost environment variable (os.Setenv) so downstream gateway code sees the override, and restores/unsets it via defer. This error wraps an os.Setenv failure. In Go that only happens for an invalid variable name or an OS-level refusal; EnvGatewayHost is a compile-time constant, so in shipped builds this is nearly unreachable.
Source
Thrown at cmd/picoclaw/internal/gateway/command.go:59
return fmt.Errorf("the --no-truncate option can only be used in conjunction with --debug (-d)")
}
if noTruncate {
utils.SetDisableTruncation(true)
logger.Info("String truncation is globally disabled via 'no-truncate' flag")
}
return nil
},
RunE: func(cmd *cobra.Command, _ []string) error {
resolvedHost, err := resolveGatewayHostOverride(cmd.Flags().Changed("host"), host)
if err != nil {
return err
}
if resolvedHost != "" {
prevHost, hadPrev := os.LookupEnv(config.EnvGatewayHost)
if err := os.Setenv(config.EnvGatewayHost, resolvedHost); err != nil {
return fmt.Errorf("failed to set %s: %w", config.EnvGatewayHost, err)
}
defer func() {
if hadPrev {
_ = os.Setenv(config.EnvGatewayHost, prevHost)
return
}
_ = os.Unsetenv(config.EnvGatewayHost)
}()
}
return gateway.Run(debug, internal.GetPicoclawHome(), internal.GetConfigPath(), allowEmpty)
},
}
cmd.Flags().BoolVarP(&debug, "debug", "d", false, "Enable debug logging")
cmd.Flags().BoolVarP(&noTruncate, "no-truncate", "T", false, "Disable string truncation in debug logs")
cmd.Flags().BoolVarP(
&allowEmpty,View on GitHub (pinned to 49183d7e8d)
Solutions
- Run without --host and set the gateway host in the config file instead
- Verify the picoclaw binary integrity and version; report it upstream if reproducible
- Check for OS environment-size limits if running under unusual wrappers
Defensive patterns
Strategy: try-catch
Validate before calling
# practically unneeded; if paranoid, verify env override works first PICOCLOW_GATEWAY_HOST=127.0.0.1 picoclaw gateway --help >/dev/null && echo env ok
Try / catch
if err := os.Setenv(config.EnvGatewayHost, host); err != nil {
// do not abort the gateway: fall back to config-file host and log loudly
logger.WarnF("host override via env failed", map[string]any{"error": err})
} Prevention
- Prefer the config-file gateway host; use --host only as an override
- Keep environment size sane in wrapper scripts
- Report reproducible occurrences upstream with the binary version
When it happens
Trigger: os.Setenv(EnvGatewayHost, resolvedHost) returning an error: effectively only a corrupted binary, an invalid constant, or an exotic platform limit (e.g. environment-size E2BIG conditions).
Common situations: Practically never seen; would indicate a build/source corruption or an unusual OS restriction rather than a user mistake.
Related errors
- invalid --host value: %w
- the --no-truncate option can only be used in conjunction wit
- --env can only be used with stdio transport
- --env-file can only be used with stdio transport
- failed to load config: %w
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/e300eb8dbe4a3152.
Report an issue: GitHub.