From a72966374fe9c88e0974036131a36a8b4201e20d Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Tue, 18 May 2021 00:28:24 +0200 Subject: [PATCH] fixes #90 --- yaml/private/internal.nim | 11 +++++------ yaml/serialization.nim | 13 +++++-------- yaml/stream.nim | 2 ++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/yaml/private/internal.nim b/yaml/private/internal.nim index 35e869d..4a1e230 100644 --- a/yaml/private/internal.nim +++ b/yaml/private/internal.nim @@ -15,13 +15,12 @@ template internalError*(s: string) = echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":" echo s when not defined(JS): - echo "[NimYAML] Stacktrace:" try: - writeStackTrace() - let exc = getCurrentException() - if not isNil(exc.parent): - echo "Internal stacktrace:" - echo getStackTrace(exc.parent) + var exc = getCurrentException() + while not isNil(exc): + echo "… stacktrace [", exc.name, ": ", exc.msg, "]" + echo getStackTrace(exc) + exc = exc.parent except: discard echo "[NimYAML] Please report this bug." quit 1 diff --git a/yaml/serialization.nim b/yaml/serialization.nim index c69770a..51add6f 100644 --- a/yaml/serialization.nim +++ b/yaml/serialization.nim @@ -1322,10 +1322,7 @@ proc construct*[T](s: var YamlStream, target: var T) except YamlConstructionError: raise (ref YamlConstructionError)(getCurrentException()) except YamlStreamError: - let cur = getCurrentException() - var e = newException(YamlStreamError, move(cur.msg)) - e.parent = cur.parent - raise e + raise (ref YamlStreamError)(getCurrentException()) except Exception: # may occur while calling s() var ex = newException(YamlStreamError, "") @@ -1335,11 +1332,11 @@ proc construct*[T](s: var YamlStream, target: var T) proc load*[K](input: Stream | string, target: var K) {.raises: [YamlConstructionError, IOError, OSError, YamlParserError].} = ## Loads a Nim value from a YAML character stream. - var - parser = initYamlParser() - events = parser.parse(input) try: - var e = events.next() + var + parser = initYamlParser() + events = parser.parse(input) + e = events.next() yAssert(e.kind == yamlStartStream) construct(events, target) e = events.next() diff --git a/yaml/stream.nim b/yaml/stream.nim index a5d8dec..3eb41bf 100644 --- a/yaml/stream.nim +++ b/yaml/stream.nim @@ -97,6 +97,8 @@ proc next*(s: YamlStream): Event {.raises: [YamlStreamError], gcSafe.} = try: while true: if s.nextImpl(s, result): break + except YamlStreamError: + raise (ref YamlStreamError)(getCurrentException()) except Exception: let cur = getCurrentException() var e = newException(YamlStreamError, cur.msg)