pulumi/pulumi · error
gathering environment metadata: %w
Error message
gathering environment metadata: %w
What it means
`pulumi destroy` failed while building the update metadata via metadata.GetUpdateMetadata. This collects environment information (execKind, execAgent, flags) and can fail when the environment or flags can't be processed. The underlying cause is wrapped.
Source
Thrown at pkg/cmd/pulumi/operations/destroy.go:269
if err := plugin.ValidatePulumiVersionRange(proj.RequiredPulumiVersion, version.Version); err != nil {
return err
}
getConfig := config.GetStackConfiguration
if stackName != "" {
// `pulumi destroy --stack <stack>` can be run outside of the project directory.
// The config may be missing, fallback on the latest configuration in the backend.
getConfig = config.GetStackConfigurationOrLatest
}
cfg, sm, err := getConfig(ctx, cmdutil.Diag(), ssml, s, proj, configFile, envOverrides)
if err != nil {
return fmt.Errorf("getting stack configuration: %w", err)
}
m, err := metadata.GetUpdateMetadata(message, root, execKind, execAgent, false, cfg, cmd.Flags())
if err != nil {
return fmt.Errorf("gathering environment metadata: %w", err)
}
cmdutil.SetStringSpanAttributes(ctx, m.Environment)
decrypter := sm.Decrypter()
encrypter := sm.Encrypter()
stackName := s.Ref().Name().String()
// Skip config validation when the program is not being run (the default for destroy),
// or when explicitly requested via --skip-config-validation. This allows stacks with
// missing or invalid config to be destroyed in scenarios such as ephemeral PR environments
// where config may diverge between branches.
if runProgram && !skipConfigValidation {
// Running the program: validate the stack config (and apply project defaults).
configError := pkgWorkspace.ValidateStackConfigAndApplyProjectConfig(
ctx,
stackName,
proj,
cfg.Environment,View on GitHub (pinned to 793f7b2e16)
Solutions
- Read the wrapped cause and fix the offending environment variable or flag
- Retry the command from a plain shell/CI step without wrappers
- Update the Pulumi CLI in case of an environment-detection bug
- File an issue with the wrapped error if the cause is unclear
Example fix
// before PULUMI_EXEC_AGENT="not-a-valid-agent" pulumi destroy // after pulumi destroy # run in a normal shell environment
Defensive patterns
Strategy: try-catch
Validate before calling
// unset odd PULUMI_* exec-agent env vars before invoking: for v in $(env | grep -o '^PULUMI_[A-Z_]*'); do unset $v; done
Try / catch
try { await pulumi.destroy(); } catch (e) { if (/gathering environment metadata/.test(e.message)) { /* retry in clean shell; report bug with wrapped cause */ } else throw e; } Prevention
- Run CLI from a plain shell/CI step without wrappers
- Keep the CLI up to date
- Avoid overriding internal PULUMI_* environment variables
When it happens
Trigger: metadata.GetUpdateMetadata(message, root, execKind, execAgent, false, cfg, cmd.Flags()) returns an error during destroy startup.
Common situations: Odd exec-agent environments (CI wrappers, shells) producing unparseable environment metadata; corrupted command flags; environment variables Pulumi expects to interpret being malformed.
Related errors
- gathering metadata: %w
- invalid --output value %q (expected %q or %q)
- getting stack configuration: %w
- validating stack config: %w
- applying stack config: %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/7fb41549a82c0ebc.
Report an issue: GitHub.