Skip to content

Commit

Permalink
Add error handling for MDBX_MAP_FULL with descriptive error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JkLondon committed Feb 5, 2025
1 parent f71fbcb commit 72f28be
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mdbx/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ var CorruptErrorHardwareRecommendations = "Maybe free space is over on disk. Oth
var CorruptErrorBacktraceRecommendations = "Otherwise - please create issue in Application repo." // with backtrace or coredump. To create coredump set compile option 'MDBX_FORCE_ASSERTIONS=1' and env variable 'GOTRACEBACK=crash'."
var CorruptErrorRecoveryRecommendations = "On default DURABLE mode, power outage can't cause this error. On other modes - power outage may break last transaction and mdbx_chk can recover db in this case, see '-t' and '-0|1|2' options."
var CorruptErrorMessage = CorruptErrorHardwareRecommendations + " " + CorruptErrorBacktraceRecommendations + " " + CorruptErrorRecoveryRecommendations
var MapFullErrorMessage = "The allocated database storage size limit has been reached."

func (e Errno) Error() string {
if e == Corrupted {
return "MDBX_FATAL: " + CorruptErrorMessage
switch e {
case Corrupted:
return fmt.Sprintf("MDBX_FATAL(%d): ", int(e)) + CorruptErrorMessage
case Panic:
return fmt.Sprintf("MDBX_PANIC(%d): ", int(e)) + CorruptErrorMessage
case MapFull:
return fmt.Sprintf("MDBX_MAP_FULL(%d)", int(e)) + MapFullErrorMessage
default:
return C.GoString(C.mdbx_strerror(C.int(e)))
}
if e == Panic {
return "MDBX_PANIC: " + CorruptErrorMessage
}
return C.GoString(C.mdbx_strerror(C.int(e)))
}

// _operrno is for use by tests that can't import C
Expand Down

0 comments on commit 72f28be

Please sign in to comment.