pulumi/pulumi · error
failed to read Pulumi config file '%s': %w
Error message
failed to read Pulumi config file '%s': %w
What it means
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.
Source
Thrown at sdk/go/common/workspace/creds.go:1172
// deleteAllBackendConfig removes all backend configuration from the default
// config file.
func deleteAllBackendConfig() error {
configFile, err := getConfigFilePath()
if err != nil {
return err
}
data, err := os.ReadFile(configFile)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("reading '%s': %w", configFile, err)
}
var config PulumiConfig
if err = json.Unmarshal(data, &config); err != nil {
return fmt.Errorf("failed to read Pulumi config file '%s': %w", configFile, err)
}
config.BackendConfig = nil
return writePulumiConfigFile(configFile, config)
}
type BackendConfig struct {
DefaultOrg string `json:"defaultOrg,omitempty"` // The default org for this backend config.
}
type PulumiConfig struct {
BackendConfig map[string]BackendConfig `json:"backends,omitempty"` // a map of arbitrary backends configs.
}
func getConfigFilePath() (string, error) {
// Allow the folder we use to store config in to be overridden by tests
pulumiFolder := os.Getenv(PulumiCredentialsPathEnvVar)
if pulumiFolder == "" {
logging.V(7).Infof("Using default Pulumi config path")View on GitHub (pinned to 793f7b2e16)
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
Example fix
// before
{ "backendConfig": "https://api.pulumi.com" }
// after
{ "backendConfig": { "url": "https://api.pulumi.com" } } Defensive patterns
Strategy: validation
Validate before calling
data, err := os.ReadFile(configFile)
if err != nil { return err }
data = bytes.TrimPrefix(data, []byte{0xEF, 0xBB, 0xBF})
var probe PulumiConfig
if err := json.Unmarshal(data, &probe); err != nil {
return fmt.Errorf("invalid Pulumi config JSON: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to read Pulumi agent config file '%s': %w
- failed to read Pulumi config file: %w
- could not parse file %s: %w
- marshalling config object: %w
- unmarshaling deployment: %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/50460df3615fa6d9.
Report an issue: GitHub.