mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: show non zero codes on bubbled error_with_code(msg,code)
errors
This commit is contained in:
parent
66a3cdec6a
commit
18cccb6caf
@ -55,6 +55,9 @@ pub:
|
||||
|
||||
// msg returns the message of MessageError
|
||||
pub fn (err MessageError) msg() string {
|
||||
if err.code > 0 {
|
||||
return '$err.msg; code: $err.code'
|
||||
}
|
||||
return err.msg
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ fn test_signal_opt_invalid_argument() {
|
||||
assert false
|
||||
}
|
||||
os.signal_opt(.kill, default_handler) or {
|
||||
assert err.msg() == 'Invalid argument'
|
||||
assert err.msg() == 'Invalid argument; code: 22'
|
||||
assert err.code() == 22
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
fn opt_err_with_code() ?string {
|
||||
return error_with_code('hi', 137)
|
||||
// TODO: remove this after the deprecation period for `?Type` representing both Result and Option passes.
|
||||
fn opt_err_with_code(code int) ?string {
|
||||
return error_with_code('hi', code)
|
||||
}
|
||||
|
||||
fn test_err_with_code() {
|
||||
if w := opt_err_with_code() {
|
||||
if w := opt_err_with_code(137) {
|
||||
assert false
|
||||
_ := w
|
||||
} else {
|
||||
assert err.msg() == 'hi'
|
||||
assert err.msg() == 'hi; code: 137'
|
||||
assert err.code() == 137
|
||||
}
|
||||
v := opt_err_with_code() or {
|
||||
assert err.msg() == 'hi'
|
||||
assert err.code() == 137
|
||||
v := opt_err_with_code(56) or {
|
||||
assert err.msg() == 'hi; code: 56'
|
||||
assert err.code() == 56
|
||||
return
|
||||
}
|
||||
assert false
|
||||
|
@ -94,3 +94,24 @@ fn test_results_if_guard() {
|
||||
}
|
||||
assert false
|
||||
}
|
||||
|
||||
fn res_err_with_code(code int) !string {
|
||||
return error_with_code('hi', code)
|
||||
}
|
||||
|
||||
fn test_err_with_code() {
|
||||
if w := res_err_with_code(137) {
|
||||
assert false
|
||||
_ := w
|
||||
} else {
|
||||
assert err.msg() == 'hi; code: 137'
|
||||
assert err.code() == 137
|
||||
}
|
||||
v := res_err_with_code(56) or {
|
||||
assert err.msg() == 'hi; code: 56'
|
||||
assert err.code() == 56
|
||||
return
|
||||
}
|
||||
assert false
|
||||
_ := v
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user