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

all: update repo to use the new error handling syntax (#8950)

This commit is contained in:
spaceface
2021-02-28 21:20:21 +01:00
committed by GitHub
parent b9a381f101
commit d63b7bc35a
135 changed files with 487 additions and 468 deletions

View File

@@ -93,17 +93,17 @@ pub fn (mut bmp BitMap) save_as_ppm(file_name string) {
bmp.format_texture()
npixels := bmp.width * bmp.height
mut f_out := os.create(file_name) or { panic(err) }
f_out.writeln('P3') or { panic(err) }
f_out.writeln('$bmp.width $bmp.height') or { panic(err) }
f_out.writeln('255') or { panic(err) }
mut f_out := os.create(file_name) or { panic(err.msg) }
f_out.writeln('P3') or { panic(err.msg) }
f_out.writeln('$bmp.width $bmp.height') or { panic(err.msg) }
f_out.writeln('255') or { panic(err.msg) }
for i in 0 .. npixels {
pos := i * bmp.bp
unsafe {
c_r := bmp.buf[pos]
c_g := bmp.buf[pos + 1]
c_b := bmp.buf[pos + 2]
f_out.write_str('$c_r $c_g $c_b ') or { panic(err) }
f_out.write_str('$c_r $c_g $c_b ') or { panic(err.msg) }
}
}
f_out.close()
@@ -127,7 +127,7 @@ pub fn (mut bmp BitMap) get_raw_bytes() []byte {
}
pub fn (mut bmp BitMap) save_raw_data(file_name string) {
os.write_file_array(file_name, bmp.get_raw_bytes()) or { panic(err) }
os.write_file_array(file_name, bmp.get_raw_bytes()) or { panic(err.msg) }
}
//

View File

@@ -156,13 +156,13 @@ fn save_raw_data_as_array(buf_bin []byte, file_name string) {
for x in buf_bin {
buf.write_string('0x${x:02x},')
}
os.write_file_array(file_name, buf.buf) or { panic(err) }
os.write_file_array(file_name, buf.buf) or { panic(err.msg) }
}
fn test_main() {
mut tf := ttf.TTF_File{}
$if create_data ? {
tf.buf = os.read_bytes(font_path) or { panic(err) }
tf.buf = os.read_bytes(font_path) or { panic(err.msg) }
println('TrueTypeFont file [$font_path] len: $tf.buf.len')
save_raw_data_as_array(tf.buf, 'test_ttf_Font_arr.bin')
} $else {
@@ -200,7 +200,7 @@ fn test_main() {
$if create_data ? {
bmp.save_as_ppm('test_ttf.ppm')
bmp.save_raw_data('test_ttf.bin')
test_buf = os.read_bytes('test_ttf.bin') or { panic(err) }
test_buf = os.read_bytes('test_ttf.bin') or { panic(err.msg) }
}
ram_buf := bmp.get_raw_bytes()

View File

@@ -18,7 +18,7 @@ fn (mut ws Client) socket_read(mut buffer []byte) ?int {
if err.code == net.err_timed_out_code {
continue
}
return error(err)
return err
}
return r
}
@@ -42,7 +42,7 @@ fn (mut ws Client) socket_read_ptr(buf_ptr byteptr, len int) ?int {
if err.code == net.err_timed_out_code {
continue
}
return error(err)
return err
}
return r
}
@@ -66,7 +66,7 @@ fn (mut ws Client) socket_write(bytes []byte) ?int {
if err.code == net.err_timed_out_code {
continue
}
return error(err)
return err
}
return n
}

View File

@@ -148,7 +148,7 @@ pub fn (mut ws Client) read_next_message() ?Message {
ws.validate_utf_8(frame.opcode, frame_payload) or {
ws.logger.error('UTF8 validation error: $err, len of payload($frame_payload.len)')
ws.send_error_event('UTF8 validation error: $err, len of payload($frame_payload.len)')
return error(err)
return err
}
msg := Message{
opcode: OPCode(frame.opcode)

View File

@@ -29,5 +29,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
// We just wanna pass text and binary message back to autobahn
return
}
ws.write(msg.payload, msg.opcode) or { panic(err) }
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
}

View File

@@ -31,5 +31,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
// We just wanna pass text and binary message back to autobahn
return
}
ws.write(msg.payload, msg.opcode) or { panic(err) }
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
}

View File

@@ -6,7 +6,7 @@ import x.websocket
fn main() {
mut s := websocket.new_server(9002, '/')
s.on_message(on_message)
s.listen() or { panic(err) }
s.listen() or { panic(err.msg) }
}
fn handle_case(case_nr int) ? {
@@ -23,5 +23,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
// We just wanna pass text and binary message back to autobahn
return
}
ws.write(msg.payload, msg.opcode) or { panic(err) }
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
}

View File

@@ -29,5 +29,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
// We just wanna pass text and binary message back to autobahn
return
}
ws.write(msg.payload, msg.opcode) or { panic(err) }
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
}

View File

@@ -31,5 +31,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? {
// We just wanna pass text and binary message back to autobahn
return
}
ws.write(msg.payload, msg.opcode) or { panic(err) }
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
}

View File

@@ -121,7 +121,7 @@ pub fn (mut ws Client) listen() ? {
}
ws.debug_log('failed to read next message: $err')
ws.send_error_event('failed to read next message: $err')
return error(err)
return err
}
if ws.state in [.closed, .closing] {
return
@@ -146,7 +146,7 @@ pub fn (mut ws Client) listen() ? {
ws.logger.error('error in message callback sending PONG: $err')
ws.send_error_event('error in message callback sending PONG: $err')
if ws.panic_on_callback {
panic(err)
panic(err.msg)
}
continue
}

View File

@@ -120,8 +120,8 @@ fn (mut s Server) serve_client(mut c Client) ? {
}
s.setup_callbacks(mut server_client)
c.listen() or {
s.logger.error(err)
return error(err)
s.logger.error(err.msg)
return err
}
}

View File

@@ -40,8 +40,8 @@ fn start_server(listen_port int) ? {
}) ?
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
match msg.opcode {
.pong { ws.write_str('pong') or { panic(err) } }
else { ws.write(msg.payload, msg.opcode) or { panic(err) } }
.pong { ws.write_str('pong') or { panic(err.msg) } }
else { ws.write(msg.payload, msg.opcode) or { panic(err.msg) } }
}
})