Show only detailed async tracebacks.
This commit is contained in:
parent
391f877e6c
commit
6301e33543
2 changed files with 19 additions and 72 deletions
|
|
@ -225,7 +225,7 @@ proc diff[T](a, b: seq[T]): (int, seq[T]) =
|
||||||
## .. code-block::nim
|
## .. code-block::nim
|
||||||
## doAssert(diff(@[1,2,42,123], @[1,2,123,678,21]) == (1, @[123,678,21]))
|
## doAssert(diff(@[1,2,42,123], @[1,2,123,678,21]) == (1, @[123,678,21]))
|
||||||
var lastIndex = 0
|
var lastIndex = 0
|
||||||
for i in 0 .. <min(a.len, b.len):
|
for i in 0..<min(a.len, b.len):
|
||||||
lastIndex = i
|
lastIndex = i
|
||||||
if a[i] != b[i]:
|
if a[i] != b[i]:
|
||||||
break
|
break
|
||||||
|
|
@ -259,62 +259,6 @@ proc mergeEntries(entries: seq[StackTraceEntry]): seq[StackTraceEntry] =
|
||||||
result.add(entry)
|
result.add(entry)
|
||||||
i.inc
|
i.inc
|
||||||
|
|
||||||
proc shortenEntries(entries: seq[StackTraceEntry]): seq[StackTraceEntry] =
|
|
||||||
## Analyzes the entries for patterns and processes them.
|
|
||||||
proc get(entries: seq[StackTraceEntry], i: int): StackTraceEntry =
|
|
||||||
if i >= entries.len:
|
|
||||||
return StackTraceEntry(procName: "", line: 0, filename: "")
|
|
||||||
else:
|
|
||||||
return entries[i]
|
|
||||||
|
|
||||||
result = @[]
|
|
||||||
var i = 0
|
|
||||||
while i < entries.len:
|
|
||||||
var entry = entries[i]
|
|
||||||
|
|
||||||
# Detect this pattern:
|
|
||||||
# (procname: a, line: 393, filename: asyncmacro.nim)
|
|
||||||
# ...
|
|
||||||
# (procname: a_continue, line: 34, filename: asyncmacro.nim)
|
|
||||||
# ...
|
|
||||||
# (procname: aIter, line: 40, filename: tasync_traceback.nim)
|
|
||||||
proc searchBackwards(entries: seq[StackTraceEntry],
|
|
||||||
current: StackTraceEntry): (int, StackTraceEntry) =
|
|
||||||
# Search backwards for the beginning of the pattern.
|
|
||||||
result[0] = 0
|
|
||||||
if not ($current.procName).normalize().endsWith("iter"):
|
|
||||||
return
|
|
||||||
|
|
||||||
# Find (procname: a, line: 393, filename: asyncmacro.nim)
|
|
||||||
let start = entries.len-1
|
|
||||||
var counter = start
|
|
||||||
while counter >= 0:
|
|
||||||
if cmpIgnoreStyle($entries[counter].procName & "iter",
|
|
||||||
$current.procName) == 0:
|
|
||||||
break
|
|
||||||
counter.dec()
|
|
||||||
|
|
||||||
# Return when no beginning of pattern is found.
|
|
||||||
if counter < 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
result[0] = start - counter
|
|
||||||
result[1] = StackTraceEntry(
|
|
||||||
procName: entries[result[0]].procName,
|
|
||||||
line: current.line,
|
|
||||||
filename: current.filename
|
|
||||||
)
|
|
||||||
|
|
||||||
let (itemsToRemove, newEntry) = searchBackwards(result, entry)
|
|
||||||
|
|
||||||
if itemsToRemove != 0:
|
|
||||||
entry = newEntry
|
|
||||||
# Remove the previous entries.
|
|
||||||
result.setLen(result.len-itemsToRemove)
|
|
||||||
|
|
||||||
result.add(entry)
|
|
||||||
i.inc
|
|
||||||
|
|
||||||
proc getHint(entry: StackTraceEntry): string =
|
proc getHint(entry: StackTraceEntry): string =
|
||||||
## We try to provide some hints about stack trace entries that the user
|
## We try to provide some hints about stack trace entries that the user
|
||||||
## may not be familiar with, in particular calls inside the stdlib.
|
## may not be familiar with, in particular calls inside the stdlib.
|
||||||
|
|
@ -372,11 +316,7 @@ proc injectStacktrace[T](future: Future[T]) =
|
||||||
var newMsg = exceptionMsg & header
|
var newMsg = exceptionMsg & header
|
||||||
|
|
||||||
let entries = getStackTraceEntries(future.error).mergeEntries()
|
let entries = getStackTraceEntries(future.error).mergeEntries()
|
||||||
let shortEntries = entries.shortenEntries()
|
newMsg.add($entries)
|
||||||
newMsg.add($shortEntries)
|
|
||||||
if entries.len > shortEntries.len:
|
|
||||||
newMsg.add("\nDetailed Async traceback:\n")
|
|
||||||
newMsg.add($entries)
|
|
||||||
|
|
||||||
newMsg.add("Exception message: " & exceptionMsg & "\n")
|
newMsg.add("Exception message: " & exceptionMsg & "\n")
|
||||||
newMsg.add("Exception type:")
|
newMsg.add("Exception type:")
|
||||||
|
|
|
||||||
|
|
@ -4,35 +4,42 @@ discard """
|
||||||
output: '''
|
output: '''
|
||||||
b failure
|
b failure
|
||||||
Async traceback:
|
Async traceback:
|
||||||
tasync_traceback.nim(75) tasync_traceback
|
tasync_traceback.nim(83) tasync_traceback
|
||||||
asyncmacro.nim(393) a
|
asyncmacro.nim(393) a
|
||||||
asyncmacro.nim(43) cb0
|
asyncmacro.nim(43) a_continue
|
||||||
└─Resumes an async procedure
|
└─Resumes an async procedure
|
||||||
asyncfutures.nim(211) callback=
|
asyncfutures.nim(211) callback=
|
||||||
asyncfutures.nim(190) addCallback
|
asyncfutures.nim(190) addCallback
|
||||||
asyncfutures.nim(53) callSoon
|
asyncfutures.nim(53) callSoon
|
||||||
asyncmacro.nim(34) cb0
|
asyncmacro.nim(34) a_continue
|
||||||
└─Resumes an async procedure
|
└─Resumes an async procedure
|
||||||
asyncmacro.nim(0) aIter
|
asyncmacro.nim(0) aIter
|
||||||
asyncfutures.nim(355) read
|
asyncfutures.nim(340) read
|
||||||
tasync_traceback.nim(73) a
|
asyncmacro.nim(34) a_continue
|
||||||
tasync_traceback.nim(70) b
|
└─Resumes an async procedure
|
||||||
|
tasync_traceback.nim(81) aIter
|
||||||
|
asyncmacro.nim(393) b
|
||||||
|
asyncmacro.nim(34) b_continue
|
||||||
|
└─Resumes an async procedure
|
||||||
|
tasync_traceback.nim(78) bIter
|
||||||
Exception message: b failure
|
Exception message: b failure
|
||||||
Exception type:
|
Exception type:
|
||||||
|
|
||||||
bar failure
|
bar failure
|
||||||
Async traceback:
|
Async traceback:
|
||||||
tasync_traceback.nim(91) tasync_traceback
|
tasync_traceback.nim(99) tasync_traceback
|
||||||
asyncdispatch.nim(1204) waitFor
|
asyncdispatch.nim(1204) waitFor
|
||||||
asyncdispatch.nim(1253) poll
|
asyncdispatch.nim(1253) poll
|
||||||
└─Processes asynchronous completion events
|
└─Processes asynchronous completion events
|
||||||
asyncdispatch.nim(181) processPendingCallbacks
|
asyncdispatch.nim(181) processPendingCallbacks
|
||||||
└─Executes pending callbacks
|
└─Executes pending callbacks
|
||||||
asyncmacro.nim(34) cb0
|
asyncmacro.nim(34) foo_continue
|
||||||
└─Resumes an async procedure
|
└─Resumes an async procedure
|
||||||
asyncmacro.nim(0) fooIter
|
asyncmacro.nim(0) fooIter
|
||||||
asyncfutures.nim(355) read
|
asyncfutures.nim(340) read
|
||||||
tasync_traceback.nim(86) barIter
|
asyncmacro.nim(34) bar_continue
|
||||||
|
└─Resumes an async procedure
|
||||||
|
tasync_traceback.nim(94) barIter
|
||||||
Exception message: bar failure
|
Exception message: bar failure
|
||||||
Exception type:'''
|
Exception type:'''
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue