{"record":{"id":"208668eb37a17b77","repo":"anomalyco/sst","slug":"errstatenotfound","errorCode":"ErrStateNotFound","errorMessage":"state not found","messagePattern":"state not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/project/provider/provider.go","lineNumber":252,"sourceCode":"\t}\n\treturn backend.putData(\"app\", app, stage, bytes.NewReader(data))\n}\n\nfunc PushSnapshot(backend Home, updateID, app, stage string, data []byte) error {\n\tslog.Info(\"pushing snapshot\", \"updateID\", updateID)\n\terr := json.Unmarshal(data, &map[string]interface{}{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"something has corrupted the state file - refusing to upload: %w\", err)\n\t}\n\treturn backend.putData(\"snapshot\", app, stage+\"/\"+updateID, bytes.NewReader(data))\n}\n\nfunc PushEventLog(backend Home, updateID, app, stage string, reader io.Reader) error {\n\tslog.Info(\"pushing eventlog\", \"updateID\", updateID)\n\treturn backend.putData(\"eventlog\", app, stage+\"/\"+updateID, reader)\n}\n\nvar ErrStateNotFound = fmt.Errorf(\"state not found\")\n\nfunc PullState(backend Home, app, stage string, out string) error {\n\tslog.Info(\"pulling state\", \"app\", app, \"stage\", stage, \"out\", out)\n\treader, err := backend.getData(\"app\", app, stage)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif reader == nil {\n\t\treturn ErrStateNotFound\n\t}\n\tfile, err := os.Create(out)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\t_, err = io.Copy(file, reader)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/project/provider/provider.go#L234-L270","documentation":"ErrStateNotFound is a sentinel error returned by provider.PullState when the backend has no state data for the requested app/stage, and surfaced through Project.Run when the initial workdir state pull finds nothing. Callers (Run in pkg/project/run.go:101) use errors.Is against it to distinguish a brand-new stage from a real backend failure.","triggerScenarios":"Calling provider.PullState(backend, app, stage, out) for a stage that has never been deployed (getData returns nil reader), or running `sst Run` with a command other than deploy/diff against a stage with no stored state.","commonSituations":"Typo in the stage or app name when pulling state; running `sst dev`/non-deploy commands against a stage that was never deployed; pointing at the wrong backend (wrong HOME/home directory or missing SST_STAGE); state was deleted or never uploaded after a first deploy.","solutions":["Verify the app and stage names are correct — a typo yields this error because no state exists under that key.","If this is genuinely a new stage, run `deploy` (or `diff`): Run auto-initializes the Pulumi stack in that case (pkg/project/run.go:105).","Confirm you are pointed at the intended backend/home; switching backend locations makes existing state appear missing.","Check the backend storage (app/stage key) actually contains state; if a previous deploy failed mid-push, redeploy to upload state."],"exampleFix":"// before\nerr := project.Run(ctx, input) // input.Command == \"refresh\", stage never deployed\n\n// after\nerr := project.Run(ctx, input)\nif errors.Is(err, provider.ErrStateNotFound) {\n\tinput.Command = \"deploy\" // deploy initializes the stack for a new stage\n\terr = project.Run(ctx, input)\n}","handlingStrategy":"try-catch","validationCode":"// No pre-call validation available; optionally probe the backend first:\nreader, err := backend.getData(\"app\", app, stage)\nhasState := err == nil && reader != nil","typeGuard":null,"tryCatchPattern":"err := provider.PullState(backend, app, stage, out)\nif errors.Is(err, provider.ErrStateNotFound) {\n\tlog.Printf(\"no existing state for %s/%s; treating as new stage\", app, stage)\n\treturn nil\n}\nif err != nil {\n\treturn err\n}","preventionTips":["Pin app/stage naming in one config source to avoid typo-driven lookups.","Confirm SST_STAGE and backend/home env vars in CI before running commands.","Always deploy a stage at least once before running refresh/destroy/dev against it.","Use errors.Is (not ==) to match this sentinel, since it may pass through wrapping."],"tags":["state","not-found","sentinel-error","backend"],"backgroundTag":"state-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}