Stricter error handling
This commit is contained in:
parent
d8ca3daf3a
commit
5498b62dbd
|
@ -3,6 +3,7 @@ type
|
||||||
UnexpectedEofError* = object of SerializationError
|
UnexpectedEofError* = object of SerializationError
|
||||||
CustomSerializationError* = object of SerializationError
|
CustomSerializationError* = object of SerializationError
|
||||||
|
|
||||||
method formatMsg*(err: ref SerializationError, filename: string): string {.gcsafe, base.} =
|
method formatMsg*(err: ref SerializationError, filename: string): string
|
||||||
|
{.gcsafe, base, raises: [Defect].} =
|
||||||
"Serialisation error while processing " & filename
|
"Serialisation error while processing " & filename
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import
|
import
|
||||||
stew/shims/macros, stew/objects
|
stew/shims/macros, stew/objects,
|
||||||
|
errors
|
||||||
|
|
||||||
type
|
type
|
||||||
FieldTag*[RecordType; fieldName: static string; FieldType] = distinct void
|
FieldTag*[RecordType; fieldName: static string; FieldType] = distinct void
|
||||||
|
@ -161,7 +162,8 @@ type
|
||||||
|
|
||||||
FieldReader*[RecordType, Reader] = tuple[
|
FieldReader*[RecordType, Reader] = tuple[
|
||||||
fieldName: string,
|
fieldName: string,
|
||||||
reader: proc (rec: var RecordType, reader: var Reader) {.gcsafe, nimcall.}
|
reader: proc (rec: var RecordType, reader: var Reader)
|
||||||
|
{.gcsafe, nimcall, raises: [SerializationError, Defect].}
|
||||||
]
|
]
|
||||||
|
|
||||||
FieldReadersTable*[RecordType, Reader] = openarray[FieldReader[RecordType, Reader]]
|
FieldReadersTable*[RecordType, Reader] = openarray[FieldReader[RecordType, Reader]]
|
||||||
|
@ -190,10 +192,11 @@ template writeFieldIMPL*[Writer](writer: var Writer,
|
||||||
|
|
||||||
proc makeFieldReadersTable(RecordType, Reader: distinct type):
|
proc makeFieldReadersTable(RecordType, Reader: distinct type):
|
||||||
seq[FieldReader[RecordType, Reader]] =
|
seq[FieldReader[RecordType, Reader]] =
|
||||||
mixin enumAllSerializedFields, readFieldIMPL
|
mixin enumAllSerializedFields, readFieldIMPL, handleReadException
|
||||||
|
|
||||||
enumAllSerializedFields(RecordType):
|
enumAllSerializedFields(RecordType):
|
||||||
proc readField(obj: var RecordType, reader: var Reader) {.gcsafe, nimcall.} =
|
proc readField(obj: var RecordType, reader: var Reader)
|
||||||
|
{.gcsafe, nimcall, raises: [SerializationError, Defect].} =
|
||||||
when RecordType is tuple:
|
when RecordType is tuple:
|
||||||
const i = fieldName.parseInt
|
const i = fieldName.parseInt
|
||||||
try:
|
try:
|
||||||
|
@ -207,8 +210,8 @@ proc makeFieldReadersTable(RecordType, Reader: distinct type):
|
||||||
# leads to an incorrect return type being reported from
|
# leads to an incorrect return type being reported from
|
||||||
# the `readFieldIMPL` function.
|
# the `readFieldIMPL` function.
|
||||||
field(obj, realFieldName) = FieldType readFieldIMPL(F, reader)
|
field(obj, realFieldName) = FieldType readFieldIMPL(F, reader)
|
||||||
except SerializationError:
|
except SerializationError as err:
|
||||||
raise
|
raise err
|
||||||
except CatchableError as err:
|
except CatchableError as err:
|
||||||
reader.handleReadException(
|
reader.handleReadException(
|
||||||
`RecordType`,
|
`RecordType`,
|
||||||
|
|
Loading…
Reference in New Issue