From 1e85116f4878b9c480db53c83445cf2b8db3667d Mon Sep 17 00:00:00 2001 From: finitemonkey <56678540+finitemonkey@users.noreply.github.com> Date: Mon, 17 Apr 2023 13:01:09 +0100 Subject: [PATCH] Separate error offset from error message --- src/jsony.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jsony.nim b/src/jsony.nim index 871dcb6..5c63c69 100644 --- a/src/jsony.nim +++ b/src/jsony.nim @@ -2,6 +2,7 @@ import jsony/objvar, std/json, std/options, std/parseutils, std/sets, std/strutils, std/tables, std/typetraits, std/unicode type JsonError* = object of ValueError + offset*: int const whiteSpace = {' ', '\n', '\t', '\r'} @@ -27,7 +28,9 @@ proc parseHook*[T: distinct](s: string, i: var int, v: var T) template error(msg: string, i: int) = ## Shortcut to raise an exception. - raise newException(JsonError, msg & " At offset: " & $i) + var e = newException(JsonError, msg) + e.offset = i + raise e template eatSpace*(s: string, i: var int) = ## Will consume whitespace.