diff --git a/nimbus/db/core_db/base.nim b/nimbus/db/core_db/base.nim index 7d30b033e..cda474a76 100644 --- a/nimbus/db/core_db/base.nim +++ b/nimbus/db/core_db/base.nim @@ -21,7 +21,7 @@ import export CoreDbBackendRef, CoreDbCaptFlags, - CoreDbError, + CoreDbErrorRef, CoreDbKvtBackendRef, CoreDbMptBackendRef, CoreDbRef, @@ -74,7 +74,7 @@ type CoreDxChldRef* = CoreDxKvtRef | CoreDxTrieRef | CoreDxTxRef | CoreDxTxID | CoreDxCaptRef | - CoreDbError | + CoreDbErrorRef | CoreDbBackendRef | CoreDbKvtBackendRef | CoreDbMptBackendRef ## Shortcut, all modules with a `parent` @@ -194,7 +194,7 @@ proc backend*(db: CoreDbRef): CoreDbBackendRef = result = db.methods.backendFn() result.parent = db -proc `$$`*(e: CoreDbError): string = +proc `$$`*(e: CoreDbErrorRef): string = ## Pretty print error symbol, note that this directive may have side effects ## as it calls a backend function. e.parent.methods.errorPrintFn(e) diff --git a/nimbus/db/core_db/base/base_desc.nim b/nimbus/db/core_db/base/base_desc.nim index 221dfc940..6df126656 100644 --- a/nimbus/db/core_db/base/base_desc.nim +++ b/nimbus/db/core_db/base/base_desc.nim @@ -31,7 +31,7 @@ const CoreDbPersistentTypes* = {LegacyDbPersistent} type - CoreDbRc*[T] = Result[T,CoreDbError] + CoreDbRc*[T] = Result[T,CoreDbErrorRef] CoreDbCaptFlags* {.pure.} = enum PersistPut @@ -68,7 +68,7 @@ type # Sub-descriptor: Misc methods for main descriptor # -------------------------------------------------- CoreDbBackendFn* = proc(): CoreDbBackendRef {.noRaise.} - CoreDbErrorPrintFn* = proc(e: CoreDbError): string {.noRaise.} + CoreDbErrorPrintFn* = proc(e: CoreDbErrorRef): string {.noRaise.} CoreDbInitLegaSetupFn* = proc() {.noRaise.} CoreDbMiscFns* = object @@ -172,7 +172,7 @@ type new*: CoreDbConstructorFns methods*: CoreDbMiscFns - CoreDbError* = object of RootObj + CoreDbErrorRef* = ref object of RootRef ## Generic error object parent*: CoreDbRef diff --git a/nimbus/db/core_db/base/validate.nim b/nimbus/db/core_db/base/validate.nim index e42ec1219..17c3f35d9 100644 --- a/nimbus/db/core_db/base/validate.nim +++ b/nimbus/db/core_db/base/validate.nim @@ -59,7 +59,8 @@ proc validateConstructors(new: CoreDbConstructorFns) = # ------------ -proc validateMethodsDesc(e: CoreDbError) = +proc validateMethodsDesc(e: CoreDbErrorRef) = + doAssert not e.isNil doAssert not e.parent.isNil proc validateMethodsDesc(eph: EphemMethodsDesc) = @@ -111,7 +112,7 @@ proc validateMethodsDesc(db: CoreDbRef) = # Public debugging helpers # ------------------------------------------------------------------------------ -proc validate*(desc: MethodsDesc | EphemMethodsDesc | CoreDbError) = +proc validate*(desc: MethodsDesc | EphemMethodsDesc | CoreDbErrorRef) = desc.validateMethodsDesc proc validate*(db: CoreDbRef) = diff --git a/nimbus/db/core_db/legacy_db.nim b/nimbus/db/core_db/legacy_db.nim index bedc9bdf8..33d439b8d 100644 --- a/nimbus/db/core_db/legacy_db.nim +++ b/nimbus/db/core_db/legacy_db.nim @@ -42,7 +42,7 @@ type LegacyCoreDbMptBE = ref object of CoreDbMptBackendRef mpt: HexaryTrie - LegacyCoreDbError = object of CoreDbError + LegacyCoreDbError = ref object of CoreDbErrorRef ctx: string ## Context where the exception or error occured name: string ## name of exception msg: string ## Exception info @@ -124,11 +124,13 @@ proc miscMethods(db: LegacyDbRef): CoreDbMiscFns = backendFn: proc(): CoreDbBackendRef = db.bless(LegacyCoreDbBE(base: db)), - errorPrintFn: proc(e: CoreDbError): string = - let e = e.LegacyCoreDbError - result &= "ctx=\"" & $e.ctx & "\"" & " , " - result &= "name=\"" & $e.name & "\"" & ", " - result &= "msg=\"" & $e.msg & "\"", + errorPrintFn: proc(e: CoreDbErrorRef): string = + if not e.isNil: + let e = e.LegacyCoreDbError + result &= "ctx=\"" & $e.ctx & "\"" & " , " + result &= "name=\"" & $e.name & "\"" & ", " + result &= "msg=\"" & $e.msg & "\"" + discard, legacySetupFn: proc() = db.tdb.put(EMPTY_ROOT_HASH.data, @[0x80u8])) diff --git a/nimbus/db/core_db/memory_only.nim b/nimbus/db/core_db/memory_only.nim index cc4e64da5..b5a567266 100644 --- a/nimbus/db/core_db/memory_only.nim +++ b/nimbus/db/core_db/memory_only.nim @@ -21,7 +21,7 @@ export # Not all symbols from the object sources will be exported by default CoreDbCaptFlags, - CoreDbError, + CoreDbErrorRef, CoreDbCaptRef, CoreDbKvtRef, CoreDbMptRef,