{"record":{"id":"e300eb8dbe4a3152","repo":"sipeed/picoclaw","slug":"failed-to-set-s-w","errorCode":null,"errorMessage":"failed to set %s: %w","messagePattern":"failed to set (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/picoclaw/internal/gateway/command.go","lineNumber":59,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"the --no-truncate option can only be used in conjunction with --debug (-d)\")\n\t\t\t}\n\n\t\t\tif noTruncate {\n\t\t\t\tutils.SetDisableTruncation(true)\n\t\t\t\tlogger.Info(\"String truncation is globally disabled via 'no-truncate' flag\")\n\t\t\t}\n\n\t\t\treturn nil\n\t\t},\n\t\tRunE: func(cmd *cobra.Command, _ []string) error {\n\t\t\tresolvedHost, err := resolveGatewayHostOverride(cmd.Flags().Changed(\"host\"), host)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif resolvedHost != \"\" {\n\t\t\t\tprevHost, hadPrev := os.LookupEnv(config.EnvGatewayHost)\n\t\t\t\tif err := os.Setenv(config.EnvGatewayHost, resolvedHost); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to set %s: %w\", config.EnvGatewayHost, err)\n\t\t\t\t}\n\t\t\t\tdefer func() {\n\t\t\t\t\tif hadPrev {\n\t\t\t\t\t\t_ = os.Setenv(config.EnvGatewayHost, prevHost)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\t_ = os.Unsetenv(config.EnvGatewayHost)\n\t\t\t\t}()\n\t\t\t}\n\n\t\t\treturn gateway.Run(debug, internal.GetPicoclawHome(), internal.GetConfigPath(), allowEmpty)\n\t\t},\n\t}\n\n\tcmd.Flags().BoolVarP(&debug, \"debug\", \"d\", false, \"Enable debug logging\")\n\tcmd.Flags().BoolVarP(&noTruncate, \"no-truncate\", \"T\", false, \"Disable string truncation in debug logs\")\n\tcmd.Flags().BoolVarP(\n\t\t&allowEmpty,","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/cmd/picoclaw/internal/gateway/command.go#L41-L77","documentation":"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.","triggerScenarios":"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).","commonSituations":"Practically never seen; would indicate a build/source corruption or an unusual OS restriction rather than a user mistake.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# practically unneeded; if paranoid, verify env override works first\nPICOCLOW_GATEWAY_HOST=127.0.0.1 picoclaw gateway --help >/dev/null && echo env ok","typeGuard":null,"tryCatchPattern":"if err := os.Setenv(config.EnvGatewayHost, host); err != nil {\n    // do not abort the gateway: fall back to config-file host and log loudly\n    logger.WarnF(\"host override via env failed\", map[string]any{\"error\": err})\n}","preventionTips":["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"],"tags":["gateway","env","cli","os"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}