From 94e7a55b97211092845d4bf4365700f38a68f300 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 18 May 2021 20:02:56 +0300 Subject: [PATCH] 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. --- vlib/builtin/option.v | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vlib/builtin/option.v b/vlib/builtin/option.v index 6ab693ac2f..90a352ffaa 100644 --- a/vlib/builtin/option.v +++ b/vlib/builtin/option.v @@ -35,10 +35,16 @@ fn (_ None__) str() string { return 'none' } +[if trace_error] +fn trace_error(x string) { + eprintln('> ${@FN} | $x') +} + // error returns a default error instance containing the error given in `message`. // Example: `if ouch { return error('an error occurred') }` [inline] pub fn error(message string) IError { + trace_error(message) return &Error{ msg: message } @@ -48,6 +54,7 @@ pub fn error(message string) IError { // `if ouch { return error_with_code('an error occurred', 1) }` [inline] pub fn error_with_code(message string, code int) IError { + trace_error('$message | code: $code') return &Error{ msg: message code: code