{"record":{"id":"e3f634862b2d0a2f","repo":"anomalyco/sst","slug":"errstagenotfound","errorCode":"ErrStageNotFound","errorMessage":"stage not found","messagePattern":"stage not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/project/stack.go","lineNumber":118,"sourceCode":"\tNew   interface{}\n}\n\ntype StackCommandEvent struct {\n\tApp     string\n\tStage   string\n\tConfig  string\n\tCommand string\n\tVersion string\n}\n\ntype Error struct {\n\tMessage string   `json:\"message\"`\n\tURN     string   `json:\"urn\"`\n\tHelp    []string `json:\"help\"`\n}\n\nvar ErrStackRunFailed = fmt.Errorf(\"stack run had errors\")\nvar ErrStageNotFound = fmt.Errorf(\"stage not found\")\nvar ErrPassphraseInvalid = fmt.Errorf(\"passphrase invalid\")\nvar ErrProtectedStage = fmt.Errorf(\"cannot remove protected stage\")\nvar ErrProtectedDevStage = fmt.Errorf(\"cannot run sst dev on protected stage\")\nvar ErrPolicyViolation = fmt.Errorf(\"policy violations detected\")\nvar ErrPolicyConfigError = fmt.Errorf(\"policy configuration error\")\n\nfunc (p *Project) ResolvePolicyPackPath(policyPath string) (string, error) {\n\tvar resolvedPath string\n\tif filepath.IsAbs(policyPath) {\n\t\tresolvedPath = policyPath\n\t} else {\n\t\tresolvedPath = filepath.Join(p.PathRoot(), policyPath)\n\t}\n\n\tif _, err := os.Stat(resolvedPath); err != nil {\n\t\treturn \"\", fmt.Errorf(\"Policy pack not found in path: %v\", resolvedPath)\n\t}\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/project/stack.go#L100-L136","documentation":"ErrStageNotFound is returned by Project.Run when the backend has no state for the app/stage and the requested command cannot operate on a nonexistent stage. Only `deploy` and `diff` may implicitly initialize a new stack; any other command on a stage with no state returns this sentinel (pkg/project/run.go:102-103).","triggerScenarios":"Calling Run with command values like `refresh`, `destroy`, `dev`, etc. against a stage that has never been deployed (underlying Pull returned provider.ErrStateNotFound).","commonSituations":"Running `sst destroy` or `sst refresh` on a stage name that was never deployed (typo or wrong SST_STAGE env); CI deploying to a new stage while a later pipeline step runs a non-deploy command before the first deploy finished; operating on the wrong backend where the stage's state doesn't exist.","solutions":["Check the stage name and SST_STAGE env for typos; confirm the stage was previously deployed (`sst deploy` at least once).","If the stage should exist, verify you're using the same backend/home as the original deploy.","If the stage is intentionally new, run `deploy` first so the stack is initialized before other commands.","Skip destroy/refresh steps in pipelines for stages that don't exist yet (guard with a state existence check)."],"exampleFix":"// before\ninput := stack.RunInput{Command: \"destroy\", Stage: \"prod\"} // stage never deployed\nerr := project.Run(ctx, input)\n\n// after\nerr := project.Run(ctx, stack.RunInput{Command: \"diff\", Stage: \"prod\"})\nif errors.Is(err, stack.ErrStageNotFound) {\n\tlog.Printf(\"stage prod does not exist; nothing to destroy\")\n\treturn nil\n}\nerr = project.Run(ctx, input)","handlingStrategy":"try-catch","validationCode":"// Probe whether the stage has state before running non-deploy commands:\nerr := project.Run(ctx, stack.RunInput{Command: \"diff\", Stage: stage})\nstageExists := !errors.Is(err, stack.ErrStageNotFound)","typeGuard":null,"tryCatchPattern":"err := project.Run(ctx, input)\nif errors.Is(err, stack.ErrStageNotFound) {\n\tlog.Printf(\"stage %s has no state; skipping %s\", input.Stage, input.Command)\n\treturn nil\n}","preventionTips":["Only run refresh/destroy on stages after confirming a prior deploy.","In pipelines, guard destroy/refresh steps with a state-existence check.","Keep stage names in a single validated config to avoid typos.","Match with errors.Is, not string comparison on the message."],"tags":["stage","not-found","sentinel-error","state"],"backgroundTag":"stage-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}