{"record":{"id":"a42b08cc52b56bd4","repo":"hashicorp/terraform","slug":"uploadsinglepartobject-data-is-empty","errorCode":null,"errorMessage":"uploadSinglePartObject: data is empty","messagePattern":"uploadSinglePartObject: data is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/oci/client.go","lineNumber":165,"sourceCode":"\t\tif err != nil && dataSize <= MaxFilePartSize {\n\t\t\tlogger.Error(fmt.Sprintf(\"Multipart upload failed, falling back to single part upload: %v\", err))\n\t\t\terr = c.uploadSinglePartObject(ctx, data, sum[:])\n\t\t}\n\t} else {\n\t\terr = c.uploadSinglePartObject(ctx, data, sum[:])\n\t}\n\tif err != nil {\n\t\treturn diags.Append(err)\n\t}\n\n\treturn diags\n}\n\nfunc (c *RemoteClient) uploadSinglePartObject(ctx context.Context, data, sum []byte) error {\n\tlogger := ctx.Value(\"logger\").(hclog.Logger).Named(\"singlePartUpload\")\n\tlogger.Info(\"Uploading single part object\")\n\tif len(data) == 0 {\n\t\treturn fmt.Errorf(\"uploadSinglePartObject: data is empty\")\n\t}\n\n\tcontentType := \"application/json\"\n\n\tputRequest := objectstorage.PutObjectRequest{\n\t\tContentType:   common.String(contentType),\n\t\tNamespaceName: common.String(c.namespace),\n\t\tObjectName:    common.String(c.path),\n\t\tBucketName:    common.String(c.bucketName),\n\t\tPutObjectBody: io.NopCloser(bytes.NewReader(data)),\n\t\tContentMD5:    common.String(base64.StdEncoding.EncodeToString(sum)),\n\t\tRequestMetadata: common.RequestMetadata{\n\t\t\tRetryPolicy: getDefaultRetryPolicy(),\n\t\t},\n\t}\n\n\t// Handle encryption settings\n\tif c.kmsKeyID != \"\" {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/remote-state/oci/client.go#L147-L183","documentation":"Raised in uploadSinglePartObject as a defensive guard when the data slice passed to the uploader is empty (len(data) == 0). Put calls uploadSinglePartObject with the serialized state, so reaching here means an empty state payload is being written. It prevents writing a 0-byte state object (which would later trip the 'object is empty' read error at client.go:123).","triggerScenarios":"RemoteClient.Put or the multipart fallback calls uploadSinglePartObject(ctx, data, sum) with len(data)==0. This happens if the state manager serializes to zero bytes, or if an internal caller invokes Put with an empty slice.","commonSituations":"An upstream bug or a custom integration calling client.Put(nil)/Put([]byte{}); a state serialization routine returning empty bytes due to a panic/short-circuit; testing harness passing empty data.","solutions":["At the call site, guard the upload: only call Put after confirming len(data) > 0 and the state serializes non-empty JSON.","Inspect the state manager output that produced the empty bytes (enable TF_LOG=TRACE) to find where serialization produced nothing.","If this is a custom integration, validate the payload before invoking Put rather than relying on this internal guard."],"exampleFix":"// before\ndiags := client.Put(data) // data may be empty\n// after\nif len(data) == 0 {\n    return tfdiags.Diagnostics{}.Append(fmt.Errorf(\"refusing to Put empty state payload\"))\n}\ndiags := client.Put(data)","handlingStrategy":"validation","validationCode":"// Validate payload size before calling Put:\nif len(data) == 0 {\n    return fmt.Errorf(\"refusing to upload empty state payload\")\n}","typeGuard":null,"tryCatchPattern":"func (c *RemoteClient) uploadSinglePartObject(ctx context.Context, data, sum []byte) error {\n    if len(data) == 0 {\n        return fmt.Errorf(\"uploadSinglePartObject: data is empty\")\n    }\n    // ...\n}","preventionTips":["Check len(data) > 0 at every call site of Put/uploadSinglePartObject.","Serialize state with a routine that cannot return empty bytes on success.","In custom integrations, validate before invoking the backend."],"tags":["oci","object-storage","put-object","validation","data-integrity","terraform-state"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}