Skip to content

Commit f6dae46

Browse files
0-8-15mgorges
andauthored
CORE: log exceptions with context (#388)
Co-authored-by: Matthias Görges <[email protected]>
1 parent ce98015 commit f6dae46

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

modules/ln_core/log.scm

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,46 +119,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119119
(log:release!)
120120
)))
121121

122-
;; try to output location of continuation
123-
;; this only works if debug information is available
124-
(define (trace:identify cont)
125-
(let ((locat (##continuation-locat cont)))
126-
(if locat
127-
(let* ((container (##locat-container locat))
128-
(path (##container->path container)))
129-
(if path
130-
(let* ((filepos (##position->filepos (##locat-position locat)))
131-
(line (fx+ (##filepos-line filepos) 1))
132-
(col (fx+ (##filepos-col filepos) 1)))
133-
(log-error "trace: " path " line=" line " col=" col))
134-
#f))
135-
#f)))
136-
137-
(define (log-trace thread)
138-
(let* ((capture (##thread-continuation-capture thread)))
139-
(let loop ((cont (##continuation-first-frame capture #f))(n 0))
140-
(if cont (begin
141-
(if (> n 1) (trace:identify cont))
142-
(loop (##continuation-next-frame cont #f)(fx+ n 1))
143-
))
144-
)
145-
))
146-
147122
(define (exception->string e)
148123
(let* ((str (with-output-to-string '() (lambda () (display-exception e (current-output-port)))))
149124
(tmp (string-split str #\newline)))
150125
(string-mapconcat (reverse tmp) ": ")))
151126

152127
(define (log:exception-handler e)
153128
(log-error "Thread \"" (thread-name (current-thread)) "\": " (exception->string e))
154-
(cond-expand
155-
(gambit-c (log-trace (current-thread)))
156-
(else
157-
(unless (deadlock-exception? e)
158-
;; gambit ___cleanup(); re-enters with a deadlock-exception here
159-
;; while printing the trace
160-
(log-trace (current-thread)))
161-
))
129+
(log-error
130+
(call-with-output-string
131+
'()
132+
(lambda (port)
133+
(continuation-capture
134+
(lambda (cont)
135+
(display-exception-in-context e cont port)
136+
(display-continuation-backtrace cont port))))))
162137
(log-error "HALT pid " ((c-lambda () int "getpid")))
163138
(exit 70))
164139

0 commit comments

Comments
 (0)