Skip to content

Commit 94e7a55

Browse files
committed
builtin: implement -d trace_error
With debugger backtraces, it can help pinpoint the original source of a bubbled error, until we can store stacktraces in the errors in an efficient way.
1 parent 9a7acd2 commit 94e7a55

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vlib/builtin/option.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ fn (_ None__) str() string {
3535
return 'none'
3636
}
3737

38+
[if trace_error]
39+
fn trace_error(x string) {
40+
eprintln('> ${@FN} | $x')
41+
}
42+
3843
// error returns a default error instance containing the error given in `message`.
3944
// Example: `if ouch { return error('an error occurred') }`
4045
[inline]
4146
pub fn error(message string) IError {
47+
trace_error(message)
4248
return &Error{
4349
msg: message
4450
}
@@ -48,6 +54,7 @@ pub fn error(message string) IError {
4854
// `if ouch { return error_with_code('an error occurred', 1) }`
4955
[inline]
5056
pub fn error_with_code(message string, code int) IError {
57+
trace_error('$message | code: $code')
5158
return &Error{
5259
msg: message
5360
code: code

0 commit comments

Comments
 (0)