{"record":{"id":"94adfd4d52030bcd","repo":"uber-go/zap","slug":"ce-message","errorCode":null,"errorMessage":"ce.Message","messagePattern":"ce\\.Message","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"zapcore/entry.go","lineNumber":196,"sourceCode":"\t// WriteThenNoop indicates that nothing special needs to be done. It's the\n\t// default behavior.\n\tWriteThenNoop CheckWriteAction = iota\n\t// WriteThenGoexit runs runtime.Goexit after Write.\n\tWriteThenGoexit\n\t// WriteThenPanic causes a panic after Write.\n\tWriteThenPanic\n\t// WriteThenFatal causes an os.Exit(1) after Write.\n\tWriteThenFatal\n)\n\n// OnWrite implements the OnWrite method to keep CheckWriteAction compatible\n// with the new CheckWriteHook interface which deprecates CheckWriteAction.\nfunc (a CheckWriteAction) OnWrite(ce *CheckedEntry, _ []Field) {\n\tswitch a {\n\tcase WriteThenGoexit:\n\t\truntime.Goexit()\n\tcase WriteThenPanic:\n\t\tpanic(ce.Message)\n\tcase WriteThenFatal:\n\t\texit.With(1)\n\t}\n}\n\nvar _ CheckWriteHook = CheckWriteAction(0)\n\n// CheckPreWriteHook is a function that transforms an Entry and its Fields\n// before they are written to cores. Register one on a CheckedEntry with the\n// Before method.\n//\n// Pre-write hooks run in the order they were added, before any Core's Write\n// method is called. They may modify the Entry and Fields freely.\ntype CheckPreWriteHook func(Entry, []Field) (Entry, []Field)\n\n// CheckedEntry is an Entry together with a collection of Cores that have\n// already agreed to log it.\n//","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/uber-go/zap/blob/bbd4ecbd8760678fdbac94c93d9aca8069c83b2f/zapcore/entry.go#L178-L214","documentation":"CheckWriteAction.OnWrite implements the post-write hook: if the action is WriteThenPanic, it panics with the checked entry's message after the log entry has been written. This is the configured behavior for Panic-level logging — the message logged is also the panic value.","triggerScenarios":"Any logger call at Panic level (logger.Panic(...), logger.Check(zapcore.PanicLevel, msg).Write(...)) with a core/hook configured with CheckWriteAction(WriteThenPanic) — the write completes, then panic(ce.Message) runs.","commonSituations":"Applications using zap's Panic-level for unrecoverable conditions, relying on a recover() in a top-level handler (HTTP middleware, worker loops) to convert the panic into a 500/retry; panics escaping tests when recover isn't set.","solutions":["If the panic is unintended, log with logger.Error instead of logger.Panic, or configure the level action as WriteThenFatal/WriteThenNoop.","Wrap entry points (HTTP handlers, goroutine bodies) with defer recover() where Panic-level logging is expected.","If you need the panic value, recover and type-assert — it is exactly the string passed to logger.Panic."],"exampleFix":"// before\nlogger.Panic(\"cache unavailable\") // panics process\n// after\nlogger.Error(\"cache unavailable\")","handlingStrategy":"try-catch","validationCode":"// Prefer Error level if panicking is undesired:\nlogger.Error(\"cache unavailable\") // instead of logger.Panic(...)","typeGuard":null,"tryCatchPattern":"func safeHandler(h http.HandlerFunc) http.HandlerFunc {\n    return func(w http.ResponseWriter, r *http.Request) {\n        defer func() {\n            if rec := recover(); rec != nil {\n                if msg, ok := rec.(string); ok {\n                    logger.Error(\"recovered panic-level log\", zap.String(\"msg\", msg))\n                }\n                http.Error(w, \"internal error\", 500)\n            }\n        }()\n        h(w, r)\n    }\n}","preventionTips":["Install a recover() middleware/decorator wherever Panic-level logging is used.","Reserve logger.Panic for truly unrecoverable conditions only.","Prefer logger.Fatal/exit hooks only when process termination is intended."],"tags":["panic","log-level","zapcore"],"backgroundTag":"panic-level-log","analyzedSha":"bbd4ecbd8760678fdbac94c93d9aca8069c83b2f","analyzedAt":"2026-08-31T13:01:40.228Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}