nwaku/waku/waku_core/topics/parsing.nim
Hanno Cornelius b9d5d28af5
chore: remove references to v2 (#1898)
* chore: remove references to v2

* fix: lingering rln-relay import path
2023-08-09 18:11:50 +01:00

37 lines
863 B
Nim

when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}
import stew/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