{"record":{"id":"62916b8286bb4a90","repo":"dgraph-io/badger","slug":"assert-failed","errorCode":null,"errorMessage":"Assert failed","messagePattern":"Assert failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"y/error.go","lineNumber":43,"sourceCode":"\nvar debugMode = false\n\n// Check logs fatal if err != nil.\nfunc Check(err error) {\n\tif err != nil {\n\t\tlog.Fatalf(\"%+v\", Wrap(err, \"\"))\n\t}\n}\n\n// Check2 acts as convenience wrapper around Check, using the 2nd argument as error.\nfunc Check2(_ interface{}, err error) {\n\tCheck(err)\n}\n\n// AssertTrue asserts that b is true. Otherwise, it would log fatal.\nfunc AssertTrue(b bool) {\n\tif !b {\n\t\tlog.Fatalf(\"%+v\", errors.New(\"Assert failed\"))\n\t}\n}\n\n// AssertTruef is AssertTrue with extra info.\nfunc AssertTruef(b bool, format string, args ...interface{}) {\n\tif !b {\n\t\tlog.Fatalf(\"%+v\", fmt.Errorf(format, args...))\n\t}\n}\n\n// Wrap wraps errors from external lib.\nfunc Wrap(err error, msg string) error {\n\tif !debugMode {\n\t\tif err == nil {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"%s err: %+v\", msg, err)\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/y/error.go#L25-L61","documentation":"Assert failed is the fatal message emitted by y.AssertTrue when its boolean condition is false: the process calls log.Fatalf and terminates immediately. It is an internal invariant check, not a recoverable error — firing means Badger reached a state the authors considered impossible (e.g. memtable capacity assumptions in ensureRoomForWrite, flushMemtable or bench harness invariants). The fault is a bug in Badger or memory corruption, not in caller input, so there is no error value to inspect; the program has already died by the time it is observed.","triggerScenarios":"Thrown at y/error.go:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Capture the fatal log output — it identifies the failing invariant and file/line; report it as a Badger issue with the stack trace and reproduction steps","Upgrade to the latest badger/v4 patch release, since many assertion bugs are fixed over time","Check for resource exhaustion (disk full, mmap failures, OOM) and hardware/disk errors that commonly trigger invariant breaks","Restore from backup into a fresh directory if a specific dataset persistently trips the assertion"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}