1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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.
This commit is contained in:
Delyan Angelov 2021-05-18 20:02:56 +03:00
parent 9a7acd244d
commit 94e7a55b97
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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