2016-09-20 19:53:38 +00:00
|
|
|
# NimYAML - YAML implementation in Nim
|
|
|
|
# (c) Copyright 2016 Felix Krause
|
|
|
|
#
|
|
|
|
# See the file "copying.txt", included in this
|
|
|
|
# distribution, for details about the copyright.
|
|
|
|
|
|
|
|
template internalError*(s: string) =
|
2018-10-09 16:25:55 +00:00
|
|
|
# Note: to get the internal stacktrace that caused the error
|
|
|
|
# compile with the `d:debug` flag.
|
2016-09-20 19:53:38 +00:00
|
|
|
when not defined(release):
|
|
|
|
let ii = instantiationInfo()
|
|
|
|
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
|
|
|
|
echo s
|
|
|
|
when not defined(JS):
|
|
|
|
echo "[NimYAML] Stacktrace:"
|
2018-10-09 16:25:55 +00:00
|
|
|
try:
|
|
|
|
writeStackTrace()
|
2018-10-11 12:21:12 +00:00
|
|
|
let exc = getCurrentException()
|
|
|
|
if not isNil(exc.parent):
|
2018-10-12 07:01:20 +00:00
|
|
|
echo "Internal stacktrace:"
|
2018-10-09 16:25:55 +00:00
|
|
|
echo getStackTrace(exc.parent)
|
2016-09-20 19:53:38 +00:00
|
|
|
except: discard
|
|
|
|
echo "[NimYAML] Please report this bug."
|
|
|
|
quit 1
|
2018-10-09 16:25:55 +00:00
|
|
|
|
2016-09-20 19:53:38 +00:00
|
|
|
template yAssert*(e: typed) =
|
|
|
|
when not defined(release):
|
|
|
|
if not e:
|
|
|
|
let ii = instantiationInfo()
|
|
|
|
echo "[NimYAML] Error in file ", ii.filename, " at line ", ii.line, ":"
|
|
|
|
echo "assertion failed!"
|
|
|
|
when not defined(JS):
|
|
|
|
echo "[NimYAML] Stacktrace:"
|
2018-10-09 16:25:55 +00:00
|
|
|
try:
|
|
|
|
writeStackTrace()
|
2018-10-11 12:21:12 +00:00
|
|
|
let exc = getCurrentException()
|
|
|
|
if not isNil(exc.parent):
|
2018-10-12 07:01:20 +00:00
|
|
|
echo "Internal stacktrace:"
|
2018-10-09 16:25:55 +00:00
|
|
|
echo getStackTrace(exc.parent)
|
2016-09-20 19:53:38 +00:00
|
|
|
except: discard
|
|
|
|
echo "[NimYAML] Please report this bug."
|
2017-02-14 18:40:40 +00:00
|
|
|
quit 1
|
|
|
|
|
|
|
|
proc yamlTestSuiteEscape*(s: string): string =
|
|
|
|
result = ""
|
|
|
|
for c in s:
|
|
|
|
case c
|
|
|
|
of '\l': result.add("\\n")
|
2017-02-14 21:22:56 +00:00
|
|
|
of '\c': result.add("\\r")
|
2017-02-14 18:40:40 +00:00
|
|
|
of '\\': result.add("\\\\")
|
2017-02-14 21:22:56 +00:00
|
|
|
of '\b': result.add("\\b")
|
|
|
|
of '\t': result.add("\\t")
|
2017-02-14 18:40:40 +00:00
|
|
|
else: result.add(c)
|