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

all: bring back panic(err.msg) -> panic(err) (#9022)

This commit is contained in:
spaceface
2021-03-01 00:18:14 +01:00
committed by GitHub
parent ce115dcbe0
commit b712af56fd
110 changed files with 383 additions and 387 deletions

View File

@ -16,7 +16,7 @@ struct User {
}
fn main() {
db := sqlite.connect(':memory:') or { panic(err.msg) }
db := sqlite.connect(':memory:') or { panic(err) }
db.exec('drop table if exists User')
db.exec("create table Module (id integer primary key, name text default '', nr_downloads int default 0, creator int default 0);")
db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")
@ -33,12 +33,12 @@ fn main() {
sql db {
insert mod into Module
}
modul := sql db {
select from Module where id == 1
}
println(modul.name)
println(modul.creator.name)
}

View File

@ -41,7 +41,7 @@ fn main() {
// by adding `limit 1` we tell V that there will be only one object
println(dash)
existing := db.select from Customer where id == 1 limit 1 or { panic(err.msg) }
existing := db.select from Customer where id == 1 limit 1 or { panic(err) }
println('Existing customer name: $existing.name')
println('Existing customer full information:')
println(existing)

View File

@ -212,13 +212,13 @@ fn (mut app App) run() {
fn init_images(mut app App) {
$if android {
background := os.read_apk_asset('img/background.png') or { panic(err.msg) }
background := os.read_apk_asset('img/background.png') or { panic(err) }
app.background = app.gg.create_image_from_byte_array(background)
bird := os.read_apk_asset('img/bird.png') or { panic(err.msg) }
bird := os.read_apk_asset('img/bird.png') or { panic(err) }
app.bird = app.gg.create_image_from_byte_array(bird)
pipetop := os.read_apk_asset('img/pipetop.png') or { panic(err.msg) }
pipetop := os.read_apk_asset('img/pipetop.png') or { panic(err) }
app.pipetop = app.gg.create_image_from_byte_array(pipetop)
pipebottom := os.read_apk_asset('img/pipebottom.png') or { panic(err.msg) }
pipebottom := os.read_apk_asset('img/pipebottom.png') or { panic(err) }
app.pipebottom = app.gg.create_image_from_byte_array(pipebottom)
} $else {
app.background = app.gg.create_image(os.resource_abs_path('assets/img/background.png'))

View File

@ -98,15 +98,15 @@ fn new_image(w int, h int) Image {
// write out a .ppm file
fn (image Image) save_as_ppm(file_name string) {
npixels := image.width * image.height
mut f_out := os.create(file_name) or { panic(err.msg) }
f_out.writeln('P3') or { panic(err.msg) }
f_out.writeln('$image.width $image.height') or { panic(err.msg) }
f_out.writeln('255') or { panic(err.msg) }
mut f_out := os.create(file_name) or { panic(err) }
f_out.writeln('P3') or { panic(err) }
f_out.writeln('$image.width $image.height') or { panic(err) }
f_out.writeln('255') or { panic(err) }
for i in 0 .. npixels {
c_r := to_int(unsafe { image.data[i] }.x)
c_g := to_int(unsafe { image.data[i] }.y)
c_b := to_int(unsafe { image.data[i] }.z)
f_out.write_str('$c_r $c_g $c_b ') or { panic(err.msg) }
f_out.write_str('$c_r $c_g $c_b ') or { panic(err) }
}
f_out.close()
}

View File

@ -10,7 +10,7 @@ fn exec(path string) string {
mut cmd := os.Command{
path: path
}
cmd.start() or { panic(err.msg) }
cmd.start() or { panic(err) }
for {
line = cmd.read_line()

View File

@ -5,7 +5,7 @@ import os
fn exec(args []string) {
os.execve('/bin/bash', args, []) or {
// eprintln(err)
panic(err.msg)
panic(err)
}
}

View File

@ -47,7 +47,7 @@ echo redirect 1 to 2 1>&2
echo line 3
'
os.write_file('/tmp/test.sh', script) or { panic(err.msg) }
os.write_file('/tmp/test.sh', script) or { panic(err) }
// os.chmod("/tmp/test.sh",0o700) //make executable
// this will work because stderr/stdout are smaller than 4096 chars, once larger there can be deadlocks

View File

@ -25,7 +25,7 @@ fn convert_html_rgb(in_col string) u32 {
query := '#([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})'
mut re := regex.regex_opt(query) or { panic(err.msg) }
mut re := regex.regex_opt(query) or { panic(err) }
start, end := re.match_string(in_col)
println('start: $start, end: $end')
mut res := u32(0)
@ -49,7 +49,7 @@ fn convert_html_rgb_n(in_col string) u32 {
query := '#(?P<red>[a-fA-F0-9]{$n_digit})(?P<green>[a-fA-F0-9]{$n_digit})(?P<blue>[a-fA-F0-9]{$n_digit})'
mut re := regex.regex_opt(query) or { panic(err.msg) }
mut re := regex.regex_opt(query) or { panic(err) }
start, end := re.match_string(in_col)
println('start: $start, end: $end')
mut res := u32(0)

View File

@ -171,12 +171,12 @@ fn data_get() []SiteConfig {
fn data_dump(data []SiteConfig) {
a := json.encode_pretty(data)
os.write_file(os.resource_abs_path('data.json'), a) or { panic(err.msg) }
os.write_file(os.resource_abs_path('data.json'), a) or { panic(err) }
}
fn data_load() []SiteConfig {
data := os.read_file(os.resource_abs_path('data.json')) or { panic(err.msg) }
a := json.decode([]SiteConfig, data) or { panic(err.msg) }
data := os.read_file(os.resource_abs_path('data.json')) or { panic(err) }
a := json.decode([]SiteConfig, data) or { panic(err) }
return a
}
@ -192,5 +192,5 @@ fn main() {
// data_dump(data)
b := filled_in_template()
println(b)
os.write_file('result.md', b) or { panic(err.msg) }
os.write_file('result.md', b) or { panic(err) }
}

View File

@ -44,7 +44,7 @@ fn (mut a App) set_status(msg string, duration_ms int) {
fn (mut a App) save() {
if a.cfile().len > 0 {
b := a.ed
os.write_file(a.cfile(), b.raw()) or { panic(err.msg) }
os.write_file(a.cfile(), b.raw()) or { panic(err) }
a.set_status('Saved', 2000)
} else {
a.set_status('No file loaded', 4000)
@ -456,7 +456,7 @@ fn (mut a App) init_file() {
// 'vico: ' +
a.tui.set_window_title(a.files[a.current_file])
mut b := a.ed
content := os.read_file(a.files[a.current_file]) or { panic(err.msg) }
content := os.read_file(a.files[a.current_file]) or { panic(err) }
b.put(content)
a.ed.cursor.pos_x = init_x
a.ed.cursor.pos_y = init_y

View File

@ -135,7 +135,7 @@ fn main() {
// load TTF fonts
for font_path in font_paths {
mut tf := ttf.TTF_File{}
tf.buf = os.read_bytes(font_path) or { panic(err.msg) }
tf.buf = os.read_bytes(font_path) or { panic(err) }
println('TrueTypeFont file [$font_path] len: $tf.buf.len')
tf.init()
println('Unit per EM: $tf.units_per_em')

View File

@ -28,7 +28,7 @@ fn start_server() ? {
for i, _ in m.clients {
mut c := m.clients[i]
if c.client.state == .open && c.client.id != ws.id {
c.client.write(msg.payload, websocket.OPCode.text_frame) or { panic(err.msg) }
c.client.write(msg.payload, websocket.OPCode.text_frame) or { panic(err) }
}
}
}, s)

View File

@ -25,7 +25,7 @@ fn start_server() ? {
return true
}) ?
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
ws.write(msg.payload, msg.opcode) or { panic(err.msg) }
ws.write(msg.payload, msg.opcode) or { panic(err) }
})
s.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
// println('client ($ws.id) closed connection')