{"record":{"id":"5aa33e1e6c217eef","repo":"chenhg5/cc-connect","slug":"generate-cron-id-w","errorCode":null,"errorMessage":"generate cron id: %w","messagePattern":"generate cron id: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/cron.go","lineNumber":739,"sourceCode":"\t} else {\n\t\tslog.Info(\"cron: job completed\", \"id\", job.ID, \"manual\", manual)\n\t}\n}\n\n// mutePlatform wraps a Platform and discards all outgoing messages.\n// Used for muted cron jobs that should execute without sending chat messages.\ntype mutePlatform struct {\n\tPlatform\n}\n\nfunc (m *mutePlatform) Reply(_ context.Context, _ any, _ string) error { return nil }\nfunc (m *mutePlatform) Send(_ context.Context, _ any, _ string) error  { return nil }\n\n\nfunc GenerateCronID() string {\n\tb := make([]byte, 4)\n\tif _, err := rand.Read(b); err != nil {\n\t\tpanic(fmt.Errorf(\"generate cron id: %w\", err))\n\t}\n\treturn hex.EncodeToString(b)\n}\n\nfunc truncateStr(s string, n int) string {\n\trunes := []rune(s)\n\tif len(runes) <= n {\n\t\treturn s\n\t}\n\treturn string(runes[:n]) + \"...\"\n}\n\nvar cronWeekdays = map[Language][7]string{\n\tLangEnglish:            {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"},\n\tLangChinese:            {\"周日\", \"周一\", \"周二\", \"周三\", \"周四\", \"周五\", \"周六\"},\n\tLangTraditionalChinese: {\"週日\", \"週一\", \"週二\", \"週三\", \"週四\", \"週五\", \"週六\"},\n\tLangJapanese:           {\"日曜\", \"月曜\", \"火曜\", \"水曜\", \"木曜\", \"金曜\", \"土曜\"},\n\tLangSpanish:            {\"domingo\", \"lunes\", \"martes\", \"miércoles\", \"jueves\", \"viernes\", \"sábado\"},","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/cron.go#L721-L757","documentation":"GenerateCronID reads 4 random bytes from crypto/rand to build a hex job id; if the OS entropy source fails, it panics with 'generate cron id: %w'. This is treated as an unrecoverable environment failure because unique ids cannot be produced without it.","triggerScenarios":"rand.Read failing due to a broken/depleted /dev/urandom, a seccomp/sandbox policy blocking the getrandom syscall, or running in a container without proper entropy device setup.","commonSituations":"Hardened containers restricting syscalls, chroot environments missing /dev/urandom, or exotic OS images with misconfigured entropy.","solutions":["Restore /dev/urandom access or unblock the getrandom syscall in the sandbox/seccomp profile","Restart the daemon on a properly configured host","Wrap the call site to recover from the panic if ids can be supplied externally"],"exampleFix":"// before\nid := core.GenerateCronID() // panics if entropy unavailable\n// after\nfunc safeCronID() (id string, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"cron id: %v\", r) } }()\n    return core.GenerateCronID(), nil\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"func safeCronID() (id string, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"generate cron id: %v\", r) } }()\n    return core.GenerateCronID(), nil\n}","preventionTips":["Ensure /dev/urandom is available and getrandom is permitted in containers/seccomp profiles","Recover from this panic at command-handler boundaries so a bad environment degrades gracefully"],"tags":["go","entropy","panic","random"],"backgroundTag":"missing-env-var","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}