pulumi/pulumi · error
internal error: %w
Error message
internal error: %w
What it means
When setting a path not under `imports`, the CLI must locate the `values` mapping in the document, creating it via YAMLSyntax.Set if missing. Failure of that internal Set (which should be impossible on a freshly created empty mapping node) is reported as 'internal error'. It signals an unexpected state in the YAML document tree manipulation code.
Source
Thrown at pkg/cmd/esc/cli/env_set.go:192
return fmt.Errorf("unmarshaling environment definition: %w", err)
}
if docNode.Kind != yaml.DocumentNode {
docNode = yaml.Node{
Kind: yaml.DocumentNode,
Content: []*yaml.Node{{}},
}
}
if path[0] == "imports" {
_, err = encoding.YAMLSyntax{Node: &docNode}.Set(nil, path, yamlValue)
} else {
valuesNode, ok := encoding.YAMLSyntax{Node: &docNode}.Get(resource.PropertyPath{"values"})
if !ok {
valuesNode, err = encoding.YAMLSyntax{Node: &docNode}.Set(nil, resource.PropertyPath{"values"}, yaml.Node{
Kind: yaml.MappingNode,
})
if err != nil {
return fmt.Errorf("internal error: %w", err)
}
}
_, err = encoding.YAMLSyntax{Node: valuesNode}.Set(nil, path, yamlValue)
}
if err != nil {
return err
}
newYAML, err := yaml.Marshal(docNode.Content[0])
if err != nil {
return fmt.Errorf("marshaling definition: %w", err)
}
diags, err := env.esc.updateEnvironment(ctx, ref, draft, newYAML, tag, "")
if err != nil {
return err
}
View on GitHub (pinned to 793f7b2e16)
Solutions
- Ensure the environment definition's top level is a YAML mapping (`values:` / `imports:` keys), not a bare scalar or list
- Rewrite the definition with `esc env edit <env>` so the root is `{}` or contains `values: {}`
- Set paths under `values` explicitly (e.g. `esc env set <env> values.mykey v`) after fixing the root
- If the document is already a valid mapping, this indicates a CLI bug — file an issue with the definition
Example fix
// before (root is a scalar)
just-a-string
// after
esc env edit my-env
values: {} Defensive patterns
Strategy: validation
Validate before calling
var doc map[string]any
if err := yaml.Unmarshal(defBytes, &doc); err != nil || doc == nil {
return fmt.Errorf("definition root must be a mapping")
} Type guard
func isMappingRoot(def []byte) bool {
var n yaml.Node
if yaml.Unmarshal(def, &n) != nil { return false }
return len(n.Content) > 0 && n.Content[0].Kind == yaml.MappingNode
} Prevention
- Keep the environment definition root as a mapping with values/imports keys
- Avoid writing bare scalars or sequences as whole definitions
- Update the CLI if this fires on a valid mapping document (likely a bug)
When it happens
Trigger: `esc env set` on a document lacking a `values` key where `encoding.YAMLSyntax.Set(nil, ["values"], ...)` returns an error — e.g. the document root resolved to a node type that cannot host a mapping (a scalar or sequence at the document root).
Common situations: An environment definition whose top level is a plain scalar or list (e.g. the file just contains `foo`) rather than a mapping, so `values` cannot be inserted as expected.
Related errors
- internal error: rendering: %w
- internal error: creating renderer: %w
- reading environment definition: %w
- marshaling environment definition: %w
- marshaling definition: %w
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/b8b0708be80f2be8.
Report an issue: GitHub.