{"record":{"id":"edb6ed6520eb1f62","repo":"pulumi/pulumi","slug":"saving-stack-config","errorCode":null,"errorMessage":"saving stack config","messagePattern":"saving stack config","errorType":"error_code","errorClass":"ErrSaveStackConfig","httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/stack/io.go","lineNumber":372,"sourceCode":"}\n\n// InitStack creates the stack.\nfunc InitStack(\n\tctx context.Context, sink diag.Sink, ws pkgWorkspace.Context, b backend.Backend, stackName string,\n\troot string, opts CreateStackOptions,\n) (backend.Stack, error) {\n\tstackRef, err := b.ParseStackReference(stackName)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn CreateStack(ctx, sink, ws, b, stackRef, root, opts)\n}\n\n// ErrSaveStackConfig wraps `SaveProjectStack` errors that occur in `CreateStack` after the\n// backend stack has already been successfully created. Callers can detect this case via\n// `errors.Is(err, ErrSaveStackConfig)` to know that the backend stack exists despite the error\n// (e.g. so they can clean it up).\nvar ErrSaveStackConfig = errors.New(\"saving stack config\")\n\n// CreateStack creates a stack with the given name, and optionally selects it as the current.\nfunc CreateStack(ctx context.Context, sink diag.Sink, ws pkgWorkspace.Context,\n\tb backend.Backend, stackRef backend.StackReference, root string, opts CreateStackOptions,\n) (backend.Stack, error) {\n\tps, needsSave, sm, err := createSecretsManagerForNewStack(\n\t\tctx, sink, ws, b, stackRef, opts.SecretsProvider, opts.ConfigFile)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create secrets manager for new stack: %w\", err)\n\t}\n\n\t// If we have a non-empty secrets manager, we'll send it off to the backend as part of the initial state to be stored\n\t// for the stack.\n\tvar initialState *apitype.UntypedDeployment\n\tif sm != nil {\n\t\tm := deploy.Manifest{\n\t\t\tTime:    time.Now(),\n\t\t\tVersion: version.Version,","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/stack/io.go#L354-L390","documentation":"ErrSaveStackConfig is a sentinel wrapping errors from SaveProjectStack that occur inside CreateStack after the backend stack has already been created successfully. Callers detect it with errors.Is(err, ErrSaveStackConfig) to know the backend stack exists despite the error, so it can be cleaned up or retried safely.","triggerScenarios":"CreateStack succeeds on the backend, needsSave is true, and SaveProjectStack then fails — e.g. the project stack config file (Pulumi.yaml) is unwritable, malformed, or the write path is invalid.","commonSituations":"Read-only working directory or repo checkout, Pulumi.yaml corrupted/locked by another process, wrong --config-file path pointing outside the project, or disk-full conditions.","solutions":["Note the backend stack WAS created; delete or reuse it before retrying (errors.Is(err, ErrSaveStackConfig))","Check write permissions on the project directory and the target config file","Validate Pulumi.yaml (or the --config-file target) is well-formed YAML and writable","Free disk space / close programs locking the file, then retry"],"exampleFix":"if err := pulumiCreateStack(...); err != nil {\n    if errors.Is(err, iostack.ErrSaveStackConfig) {\n        // backend stack exists despite save failure — clean up or proceed\n        log.Println(\"stack exists on backend; fixing local config only\")\n    }\n}","handlingStrategy":"type-guard","validationCode":"// ensure the project config file is writable before creating\ninfo, err := os.Stat(filepath.Join(root, \"Pulumi.yaml\"))\nif err == nil && info.Mode().Perm()&0200 == 0 {\n    return errors.New(\"Pulumi.yaml is not writable\")\n}","typeGuard":"func isSaveStackConfigErr(err error) bool {\n    return errors.Is(err, iostack.ErrSaveStackConfig)\n}","tryCatchPattern":"if err != nil {\n    if errors.Is(err, iostack.ErrSaveStackConfig) {\n        // backend stack exists despite save failure: cleanup or adopt\n        b.DeleteStack(ctx, ref)\n    }\n    return err\n}","preventionTips":["Run stack creation in writable working directories","Validate Pulumi.yaml parses before programmatic stack creation","Check --config-file target exists and is writable"],"tags":["cli","stack-creation","filesystem","sentinel-error"],"backgroundTag":"stack-config-save-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}