{"record":{"id":"b8b0708be80f2be8","repo":"pulumi/pulumi","slug":"internal-error-w","errorCode":null,"errorMessage":"internal error: %w","messagePattern":"internal error: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/esc/cli/env_set.go","lineNumber":192,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"unmarshaling environment definition: %w\", err)\n\t\t\t}\n\t\t\tif docNode.Kind != yaml.DocumentNode {\n\t\t\t\tdocNode = yaml.Node{\n\t\t\t\t\tKind:    yaml.DocumentNode,\n\t\t\t\t\tContent: []*yaml.Node{{}},\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif path[0] == \"imports\" {\n\t\t\t\t_, err = encoding.YAMLSyntax{Node: &docNode}.Set(nil, path, yamlValue)\n\t\t\t} else {\n\t\t\t\tvaluesNode, ok := encoding.YAMLSyntax{Node: &docNode}.Get(resource.PropertyPath{\"values\"})\n\t\t\t\tif !ok {\n\t\t\t\t\tvaluesNode, err = encoding.YAMLSyntax{Node: &docNode}.Set(nil, resource.PropertyPath{\"values\"}, yaml.Node{\n\t\t\t\t\t\tKind: yaml.MappingNode,\n\t\t\t\t\t})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"internal error: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_, err = encoding.YAMLSyntax{Node: valuesNode}.Set(nil, path, yamlValue)\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tnewYAML, err := yaml.Marshal(docNode.Content[0])\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"marshaling definition: %w\", err)\n\t\t\t}\n\n\t\t\tdiags, err := env.esc.updateEnvironment(ctx, ref, draft, newYAML, tag, \"\")\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/esc/cli/env_set.go#L174-L210","documentation":"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.","triggerScenarios":"`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).","commonSituations":"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.","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"],"exampleFix":"// before (root is a scalar)\njust-a-string\n// after\nesc env edit my-env\nvalues: {}","handlingStrategy":"validation","validationCode":"var doc map[string]any\nif err := yaml.Unmarshal(defBytes, &doc); err != nil || doc == nil {\n    return fmt.Errorf(\"definition root must be a mapping\")\n}","typeGuard":"func isMappingRoot(def []byte) bool {\n    var n yaml.Node\n    if yaml.Unmarshal(def, &n) != nil { return false }\n    return len(n.Content) > 0 && n.Content[0].Kind == yaml.MappingNode\n}","tryCatchPattern":null,"preventionTips":["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)"],"tags":["cli","yaml","internal","esc"],"backgroundTag":"yaml-document-structure-invalid","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}