mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-16 18:06:45 +00:00
fd6a71cdd7
* bump_dependencies.md: add nim-results dependency * change imports stew/results to results * switching to Nim 2.0.8 * waku.nimble: reflect the requirement nim 1.6.0 to 2.0.8 Adding --mm:refc as nim 2.0 enables a new garbage collector that we're not yet ready to support * adapt waku code to Nim 2.0 * gcsafe adaptations because Nim 2.0 is more strict
31 lines
781 B
Nim
31 lines
781 B
Nim
{.push raises: [].}
|
|
|
|
import results
|
|
|
|
type
|
|
ParsingErrorKind* {.pure.} = enum
|
|
InvalidFormat
|
|
MissingPart
|
|
|
|
ParsingError* = object
|
|
case kind*: ParsingErrorKind
|
|
of InvalidFormat:
|
|
cause*: string
|
|
of MissingPart:
|
|
part*: string
|
|
|
|
type ParsingResult*[T] = Result[T, ParsingError]
|
|
|
|
proc invalidFormat*(T: type ParsingError, cause = "invalid format"): T =
|
|
ParsingError(kind: ParsingErrorKind.InvalidFormat, cause: cause)
|
|
|
|
proc missingPart*(T: type ParsingError, part = "unknown"): T =
|
|
ParsingError(kind: ParsingErrorKind.MissingPart, part: part)
|
|
|
|
proc `$`*(err: ParsingError): string =
|
|
case err.kind
|
|
of ParsingErrorKind.InvalidFormat:
|
|
return "invalid format: " & err.cause
|
|
of ParsingErrorKind.MissingPart:
|
|
return "missing part: " & err.part
|