{"record":{"id":"0fee72988874854d","repo":"larksuite/cli","slug":"failed-to-generate-cid-w","errorCode":null,"errorMessage":"failed to generate CID: %w","messagePattern":"failed to generate CID: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":1012,"sourceCode":"// or protocol-relative URL (//host/...) is rejected.\nfunc isLocalFileSrc(src string) bool {\n\ttrimmed := strings.TrimSpace(src)\n\tif trimmed == \"\" {\n\t\treturn false\n\t}\n\tif strings.HasPrefix(trimmed, \"//\") {\n\t\treturn false\n\t}\n\treturn !uriSchemeRegexp.MatchString(trimmed)\n}\n\n// generateCID returns a random UUID string suitable for use as a Content-ID.\n// UUIDs contain only [0-9a-f-], which is inherently RFC-safe and unique,\n// avoiding all filename-derived encoding/collision issues.\nfunc generateCID() (string, error) {\n\tid, err := uuid.NewRandom()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to generate CID: %w\", err)\n\t}\n\treturn id.String(), nil\n}\n\n// LocalImageRef represents a local image found in an HTML body that needs\n// to be embedded as an inline MIME part.\ntype LocalImageRef struct {\n\tFilePath string // original src value from the HTML\n\tCID      string // generated Content-ID\n}\n\n// ResolveLocalImagePaths scans HTML for <img src=\"local/path\"> references,\n// validates each path, generates CIDs, and returns the modified HTML with\n// cid: URIs plus the list of local image references to embed as inline parts.\n// This function handles only the HTML transformation; callers are responsible\n// for embedding the actual file data (e.g., via emlbuilder.AddFileInline).\nfunc ResolveLocalImagePaths(html string) (string, []LocalImageRef, error) {\n\tmatches := imgSrcRegexp.FindAllStringSubmatchIndex(html, -1)","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L994-L1030","documentation":"generateCID creates a random UUID used as a Content-ID; if the crypto/random source fails (uuid.NewRandom error), the failure is wrapped with this message. UUIDs are used precisely to avoid filename-derived cid issues, so a generation failure means the environment's randomness source is unavailable.","triggerScenarios":"uuid.NewRandom failing due to the OS entropy source being unavailable (e.g. /dev/urandom inaccessible, restricted container, low-level crypto/rand error) during ResolveLocalImagePaths inline embedding.","commonSituations":"Sandboxes or hardened containers blocking /dev/urandom; memory/exhaustion errors from crypto/rand; unusual OS images without a random device.","solutions":["Restore access to the system entropy source (/dev/urandom) or fix the crypto/rand failure reported in the wrapped cause","Retry the operation once the environment issue is fixed","Check the wrapped cause (%w) for the underlying OS error to pinpoint the environment problem"],"exampleFix":"# before (restricted container)\ndocker run --security-opt ... image  # /dev/urandom blocked\n# after\n# allow device access or run with default seccomp so crypto/rand works\ndocker run image","handlingStrategy":"retry","validationCode":"if _, err := uuid.NewRandom(); err != nil {\n\t// entropy source unavailable — fix environment (e.g. /dev/urandom access) before running\n}","typeGuard":null,"tryCatchPattern":"cid, err := generateCID()\nif err != nil {\n\t// inspect wrapped cause for OS/crypto/rand error; repair entropy source, then retry\n\treturn fmt.Errorf(\"cid generation failed: %w\", err)\n}","preventionTips":["Run in environments with a working entropy source (default seccomp, /dev/urandom accessible)","Log the wrapped cause to identify the underlying OS error","Retry once transient resource issues are resolved; persisting failure is environmental"],"tags":["mail","draft","cid","uuid","randomness"],"backgroundTag":"random-source-unavailable","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"}