nim-serde/serde/cbor/errors.nim

39 lines
1.3 KiB
Nim
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# This file is a modified version of Emery Hemingways CBOR library for Nim,
# originally available at https://github.com/ehmry/cbor-nim and released under The Unlicense.
import ../utils/types
import ./types
import std/sets
proc newUnexpectedKindError*(
expectedType: type, expectedKinds: string, cbor: CborNode
): ref UnexpectedKindError =
newException(
UnexpectedKindError,
"deserialization to " & $expectedType & " failed: expected " & expectedKinds &
" but got " & $cbor.kind,
)
proc newUnexpectedKindError*(
expectedType: type, expectedKinds: set[CborEventKind], cbor: CborNode
): ref UnexpectedKindError =
newUnexpectedKindError(expectedType, $expectedKinds, cbor)
proc newUnexpectedKindError*(
expectedType: type, expectedKind: CborEventKind, cbor: CborNode
): ref UnexpectedKindError =
newUnexpectedKindError(expectedType, {expectedKind}, cbor)
proc newUnexpectedKindError*(
expectedType: type, expectedKinds: set[CborNodeKind], cbor: CborNode
): ref UnexpectedKindError =
newUnexpectedKindError(expectedType, $expectedKinds, cbor)
proc newUnexpectedKindError*(
expectedType: type, expectedKind: CborNodeKind, cbor: CborNode
): ref UnexpectedKindError =
newUnexpectedKindError(expectedType, {expectedKind}, cbor)
proc newCborError*(msg: string): ref CborParseError =
newException(CborParseError, msg)