{"record":{"id":"50460df3615fa6d9","repo":"pulumi/pulumi","slug":"failed-to-read-pulumi-config-file-s-w","errorCode":null,"errorMessage":"failed to read Pulumi config file '%s': %w","messagePattern":"failed to read Pulumi config file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/common/workspace/creds.go","lineNumber":1172,"sourceCode":"\n// deleteAllBackendConfig removes all backend configuration from the default\n// config file.\nfunc deleteAllBackendConfig() error {\n\tconfigFile, err := getConfigFilePath()\n\tif err != nil {\n\t\treturn err\n\t}\n\tdata, err := os.ReadFile(configFile)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"reading '%s': %w\", configFile, err)\n\t}\n\n\tvar config PulumiConfig\n\tif err = json.Unmarshal(data, &config); err != nil {\n\t\treturn fmt.Errorf(\"failed to read Pulumi config file '%s': %w\", configFile, err)\n\t}\n\tconfig.BackendConfig = nil\n\treturn writePulumiConfigFile(configFile, config)\n}\n\ntype BackendConfig struct {\n\tDefaultOrg string `json:\"defaultOrg,omitempty\"` // The default org for this backend config.\n}\n\ntype PulumiConfig struct {\n\tBackendConfig map[string]BackendConfig `json:\"backends,omitempty\"` // a map of arbitrary backends configs.\n}\n\nfunc getConfigFilePath() (string, error) {\n\t// Allow the folder we use to store config in to be overridden by tests\n\tpulumiFolder := os.Getenv(PulumiCredentialsPathEnvVar)\n\tif pulumiFolder == \"\" {\n\t\tlogging.V(7).Infof(\"Using default Pulumi config path\")","sourceCodeStart":1154,"sourceCodeEnd":1190,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/common/workspace/creds.go#L1154-L1190","documentation":"This error means the Pulumi config file was read successfully but its contents could not be parsed into PulumiConfig via json.Unmarshal. The library throws it so a malformed config is surfaced instead of being silently overwritten with BackendConfig cleared.","triggerScenarios":"The config file contains invalid JSON or JSON with unexpected types for PulumiConfig fields (e.g. backendConfig as a string instead of object), causing json.Unmarshal to fail.","commonSituations":"Manual editing introduced a trailing comma or comments (JSON has neither); file truncated by a crash; file written by an older/different tool version with a divergent schema.","solutions":["Run the file through `jq . <configFile>` to find and fix the JSON syntax error","Restore from backup or delete the file and let pulumi regenerate it","Remove JSON comments and trailing commas — the parser is strict encoding/json","If types are wrong (e.g. backendConfig not an object), correct the JSON structure to match PulumiConfig"],"exampleFix":"// before\n{ \"backendConfig\": \"https://api.pulumi.com\" }\n// after\n{ \"backendConfig\": { \"url\": \"https://api.pulumi.com\" } }","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(configFile)\nif err != nil { return err }\ndata = bytes.TrimPrefix(data, []byte{0xEF, 0xBB, 0xBF})\nvar probe PulumiConfig\nif err := json.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"invalid Pulumi config JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run jq . on the config after any manual edit","Remove comments and trailing commas — encoding/json is strict","Strip UTF-8 BOM if the file came from Windows editors","Back up config.json before schema-affecting CLI upgrades"],"tags":["go","json","config-file","corruption"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}