This commit is contained in:
Felix Krause 2021-05-18 00:28:24 +02:00
parent f123924d32
commit a72966374f
3 changed files with 12 additions and 14 deletions

View File

@ -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

View File

@ -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()

View File

@ -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)