{"record":{"id":"aae62e9f5ecb37e4","repo":"larksuite/cli","slug":"draft-snapshot-is-empty","errorCode":null,"errorMessage":"draft snapshot is empty","messagePattern":"draft snapshot is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/serialize.go","lineNumber":19,"sourceCode":"// Copyright (c) 2026 Lark Technologies Pte. Ltd.\n// SPDX-License-Identifier: MIT\n\n//nolint:forbidigo // intermediate draft serializer errors; mail command layer wraps into typed ValidationError.\npackage draft\n\nimport (\n\t\"bytes\"\n\t\"encoding/base64\"\n\t\"fmt\"\n\t\"math/rand\"\n\t\"mime\"\n\t\"mime/quotedprintable\"\n\t\"strings\"\n)\n\nfunc Serialize(snapshot *DraftSnapshot) (string, error) {\n\tif snapshot == nil || snapshot.Body == nil {\n\t\treturn \"\", fmt.Errorf(\"draft snapshot is empty\")\n\t}\n\tvar buf bytes.Buffer\n\tmimeVersionValue := \"1.0\"\n\twroteMimeVersion := false\n\tfor _, header := range snapshot.Headers {\n\t\tif strings.EqualFold(header.Name, \"MIME-Version\") {\n\t\t\tmimeVersionValue = header.Value\n\t\t\twriteHeader(&buf, header.Name, header.Value)\n\t\t\twroteMimeVersion = true\n\t\t\tcontinue\n\t\t}\n\t\tif isBodyHeader(header.Name) {\n\t\t\tcontinue\n\t\t}\n\t\twriteHeader(&buf, header.Name, header.Value)\n\t}\n\tif !wroteMimeVersion {\n\t\twriteHeader(&buf, \"MIME-Version\", mimeVersionValue)","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/serialize.go#L1-L37","documentation":"Serialize renders a DraftSnapshot back into an RFC 2822 MIME string. It requires a non-nil snapshot with a non-nil Body; anything else cannot be serialized, so it fails immediately with this error before writing any output. It guards against serializing half-constructed or reset snapshots.","triggerScenarios":"Calling Serialize (directly or via draft save flows, as in the acceptance tests) with a nil *DraftSnapshot or a snapshot whose Body field was never initialized.","commonSituations":"Zero-value DraftSnapshot returned by a failed load; a snapshot reset/cleared between deserialize and serialize; forgetting to run the parse/build step before saving.","solutions":["Ensure the snapshot was produced by a successful Deserialize/set_body before serializing","Check that snapshot.Body is non-nil before calling Serialize","Fix the earlier load/build failure that left the snapshot empty instead of serializing anyway"],"exampleFix":"// before\nout, err := draft.Serialize(snap) // snap.Body == nil\n// after\nif snap == nil || snap.Body == nil { return fmt.Errorf(\"draft not loaded\") }\nout, err := draft.Serialize(snap)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func serializable(s *DraftSnapshot) bool { return s != nil && s.Body != nil }","tryCatchPattern":"out, err := draft.Serialize(snap)\nif err != nil {\n  if strings.Contains(err.Error(), \"draft snapshot is empty\") {\n    return reloadDraft() // rebuild snapshot from source before saving\n  }\n  return err\n}","preventionTips":["Only serialize snapshots produced by a successful Deserialize or build step","Check snap.Body != nil before saving","Handle upstream load failures instead of serializing a zero-value snapshot"],"tags":["mail","serialize","draft","precondition"],"backgroundTag":"empty-draft-snapshot","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}