{"record":{"id":"f6a5472059e6ff00","repo":"anomalyco/sst","slug":"something-has-corrupted-the-state-file-refusing","errorCode":null,"errorMessage":"something has corrupted the state file - refusing to upload: %w","messagePattern":"something has corrupted the state file - refusing to upload: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/project/provider/provider.go","lineNumber":233,"sourceCode":"\treturn data, err\n}\n\nfunc PutSecrets(backend Home, app, stage string, data map[string]string) error {\n\tif stage == \"\" {\n\t\tstage = \"_fallback\"\n\t}\n\tslog.Info(\"putting secrets\", \"app\", app, \"stage\", stage)\n\tif data == nil {\n\t\treturn nil\n\t}\n\treturn putData(backend, \"secret\", app, stage, true, data)\n}\n\nfunc PushPartialState(backend Home, updateID, app, stage string, data []byte) error {\n\tslog.Info(\"pushing partial state\", \"updateID\", updateID)\n\terr := json.Unmarshal(data, &map[string]interface{}{})\n\tif err != nil || len(data) == 0 {\n\t\treturn fmt.Errorf(\"something has corrupted the state file - refusing to upload: %w\", err)\n\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","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/project/provider/provider.go#L215-L251","documentation":"`PushPartialState` validates the state payload is non-empty, valid JSON before uploading it to the backend. If `json.Unmarshal` fails or the payload is empty, it refuses the upload because a corrupt/empty state file would destroy the stage's state. Note `err` may be nil when only the empty-length check triggers, producing a `%!w(<nil>)` message.","triggerScenarios":"The Pulumi automation engine hands SST an empty or non-JSON partial state blob — typically after a crashed deployment, corrupted local state, or a disk/full-write issue mid-update.","commonSituations":"Deploy interrupted by OOM or power loss; local `.pulumi/state` corruption; running SST on a filesystem that truncated the temp state file.","solutions":["Inspect the local state for corruption and restore from a snapshot (`sst state` tooling or Pulumi export/import depending on flow)","Re-run the deployment from a clean state; if the stage state is unrecoverable, restore from the backend's last good state or snapshot","Free disk space / fix environment issues that truncated the file, then retry"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const data = readStateFile();\nif (!data || !data.length) throw new Error(\"empty state, refusing to push\");\nJSON.parse(data.toString(\"utf8\")); // throws before upload if corrupt","typeGuard":"function isValidStatePayload(data: Buffer): boolean {\n  if (!data || data.length === 0) return false;\n  try { JSON.parse(data.toString(\"utf8\")); return true; } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Avoid interrupting deploys mid-write (watch for OOM/disk-full)","Keep a recent snapshot/export of stage state before risky operations","Restore corrupt local state from the backend's last good copy before re-deploying"],"tags":["state","json","validation","state-upload"],"backgroundTag":"corrupt-state-file","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}