mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -04:00
builtin: simplify MessageError.msg() (#21524)
This commit is contained in:
parent
c8bf38ccb3
commit
3a3a1085cf
@ -32,7 +32,7 @@ pub fn (err IError) str() string {
|
|||||||
err.msg()
|
err.msg()
|
||||||
}
|
}
|
||||||
MessageError {
|
MessageError {
|
||||||
err.msg()
|
err.str()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// >> Hack to allow old style custom error implementations
|
// >> Hack to allow old style custom error implementations
|
||||||
@ -68,6 +68,11 @@ pub:
|
|||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// str returns the message and code of the MessageError
|
||||||
|
pub fn (err MessageError) str() string {
|
||||||
|
return err.msg
|
||||||
|
}
|
||||||
|
|
||||||
// msg returns the message of the MessageError
|
// msg returns the message of the MessageError
|
||||||
pub fn (err MessageError) msg() string {
|
pub fn (err MessageError) msg() string {
|
||||||
return err.msg
|
return err.msg
|
||||||
|
@ -40,7 +40,7 @@ pub fn (err IError) str() string {
|
|||||||
err.msg()
|
err.msg()
|
||||||
}
|
}
|
||||||
MessageError {
|
MessageError {
|
||||||
err.msg()
|
(*err).str()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// >> Hack to allow old style custom error implementations
|
// >> Hack to allow old style custom error implementations
|
||||||
@ -70,15 +70,20 @@ pub:
|
|||||||
code int
|
code int
|
||||||
}
|
}
|
||||||
|
|
||||||
// msg returns the message of MessageError
|
// str returns both the .msg and .code of MessageError, when .code is != 0
|
||||||
pub fn (err MessageError) msg() string {
|
pub fn (err MessageError) str() string {
|
||||||
if err.code > 0 {
|
if err.code > 0 {
|
||||||
return '${err.msg}; code: ${err.code}'
|
return '${err.msg}; code: ${err.code}'
|
||||||
}
|
}
|
||||||
return err.msg
|
return err.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// code returns the code of MessageError
|
// msg returns only the message of MessageError
|
||||||
|
pub fn (err MessageError) msg() string {
|
||||||
|
return err.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// code returns only the code of MessageError
|
||||||
pub fn (err MessageError) code() int {
|
pub fn (err MessageError) code() int {
|
||||||
return err.code
|
return err.code
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,8 @@ fn test_signal_opt_invalid_argument() {
|
|||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
os.signal_opt(.kill, default_handler) or {
|
os.signal_opt(.kill, default_handler) or {
|
||||||
assert err.msg() == 'Invalid argument; code: 22'
|
assert err.str() == 'Invalid argument; code: 22'
|
||||||
|
assert err.msg() == 'Invalid argument'
|
||||||
assert err.code() == 22
|
assert err.code() == 22
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) (bool, bool) {
|
|||||||
}
|
}
|
||||||
ast.PostfixExpr {
|
ast.PostfixExpr {
|
||||||
ifdef := g.comptime_if_to_ifdef((cond.expr as ast.Ident).name, true) or {
|
ifdef := g.comptime_if_to_ifdef((cond.expr as ast.Ident).name, true) or {
|
||||||
verror(err.msg())
|
verror(err.str())
|
||||||
return false, true
|
return false, true
|
||||||
}
|
}
|
||||||
g.write('defined(${ifdef})')
|
g.write('defined(${ifdef})')
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
================ V panic ================
|
================ V panic ================
|
||||||
module: main
|
module: main
|
||||||
function: main()
|
function: main()
|
||||||
message: no such table: User (1) (INSERT INTO `User` (`id`, `name`) VALUES (?1, ?2);); code: 1
|
message: no such table: User (1) (INSERT INTO `User` (`id`, `name`) VALUES (?1, ?2);)
|
||||||
file: vlib/v/slow_tests/inout/orm_panic_for_insert_into_not_created_table.vv:17
|
file: vlib/v/slow_tests/inout/orm_panic_for_insert_into_not_created_table.vv:17
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
================ V panic ================
|
================ V panic ================
|
||||||
module: main
|
module: main
|
||||||
function: main()
|
function: main()
|
||||||
message: no such table: User (1) (SELECT `id`, `name` FROM `User`;); code: 1
|
message: no such table: User (1) (SELECT `id`, `name` FROM `User`;)
|
||||||
file: vlib/v/slow_tests/inout/orm_panic_for_select_from_not_created_table.vv:13
|
file: vlib/v/slow_tests/inout/orm_panic_for_select_from_not_created_table.vv:13
|
||||||
|
@ -8,11 +8,13 @@ fn test_err_with_code() {
|
|||||||
assert false
|
assert false
|
||||||
_ := w
|
_ := w
|
||||||
} else {
|
} else {
|
||||||
assert err.msg() == 'hi; code: 137'
|
assert err.str() == 'hi; code: 137'
|
||||||
|
assert err.msg() == 'hi'
|
||||||
assert err.code() == 137
|
assert err.code() == 137
|
||||||
}
|
}
|
||||||
v := opt_err_with_code(56) or {
|
v := opt_err_with_code(56) or {
|
||||||
assert err.msg() == 'hi; code: 56'
|
assert err.str() == 'hi; code: 56'
|
||||||
|
assert err.msg() == 'hi'
|
||||||
assert err.code() == 56
|
assert err.code() == 56
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -297,7 +299,7 @@ fn test_option_void_return_types_of_anon_fn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
f fn (int) !
|
f fn (int) ! = unsafe { nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_option_void_return_types_of_anon_fn_in_struct() {
|
fn test_option_void_return_types_of_anon_fn_in_struct() {
|
||||||
|
@ -104,11 +104,13 @@ fn test_err_with_code() {
|
|||||||
assert false
|
assert false
|
||||||
_ := w
|
_ := w
|
||||||
} else {
|
} else {
|
||||||
assert err.msg() == 'hi; code: 137'
|
assert err.str() == 'hi; code: 137'
|
||||||
|
assert err.msg() == 'hi'
|
||||||
assert err.code() == 137
|
assert err.code() == 137
|
||||||
}
|
}
|
||||||
v := res_err_with_code(56) or {
|
v := res_err_with_code(56) or {
|
||||||
assert err.msg() == 'hi; code: 56'
|
assert err.str() == 'hi; code: 56'
|
||||||
|
assert err.msg() == 'hi'
|
||||||
assert err.code() == 56
|
assert err.code() == 56
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
http_port := os.args[1].int()
|
http_port := os.args[1].int()
|
||||||
assert http_port > 0
|
assert http_port > 0
|
||||||
timeout := os.args[2].int()
|
|
||||||
mut app_dup := &App{
|
mut app_dup := &App{
|
||||||
controllers: [
|
controllers: [
|
||||||
vweb.controller('/admin', &Admin{}),
|
vweb.controller('/admin', &Admin{}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user