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

pull/9022/head
spaceface 2021-02-28 21:20:21 +01:00 committed by GitHub
parent b9a381f101
commit d63b7bc35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
135 changed files with 487 additions and 468 deletions

View File

@ -81,7 +81,7 @@ fn main() {
} }
fn exec(s string) string { fn exec(s string) string {
e := os.exec(s) or { panic(err) } e := os.exec(s) or { panic(err.msg) }
return e.output.trim_right('\r\n') return e.output.trim_right('\r\n')
} }
@ -111,7 +111,7 @@ fn measure(cmd string, description string) int {
} }
fn measure_steps(vdir string) (int, int, int) { fn measure_steps(vdir string) (int, int, int) {
resp := os.exec('$vdir/vprod -o v.c -show-timings $vdir/cmd/v') or { panic(err) } resp := os.exec('$vdir/vprod -o v.c -show-timings $vdir/cmd/v') or { panic(err.msg) }
lines := resp.output.split_into_lines() lines := resp.output.split_into_lines()
if lines.len != 3 { if lines.len != 3 {
return 0, 0, 0 return 0, 0, 0

View File

@ -210,7 +210,7 @@ fn (mut gen_vc GenVC) generate() {
// check if gen_vc dir exists // check if gen_vc dir exists
if !os.is_dir(gen_vc.options.work_dir) { if !os.is_dir(gen_vc.options.work_dir) {
// try create // try create
os.mkdir(gen_vc.options.work_dir) or { panic(err) } os.mkdir(gen_vc.options.work_dir) or { panic(err.msg) }
// still dosen't exist... we have a problem // still dosen't exist... we have a problem
if !os.is_dir(gen_vc.options.work_dir) { if !os.is_dir(gen_vc.options.work_dir) {
gen_vc.logger.error('error creating directory: $gen_vc.options.work_dir') gen_vc.logger.error('error creating directory: $gen_vc.options.work_dir')
@ -246,8 +246,8 @@ fn (mut gen_vc GenVC) generate() {
ts_v := git_log_v.find_between('Date:', '\n').trim_space() ts_v := git_log_v.find_between('Date:', '\n').trim_space()
ts_vc := git_log_vc.find_between('Date:', '\n').trim_space() ts_vc := git_log_vc.find_between('Date:', '\n').trim_space()
// parse time as string to time.Time // parse time as string to time.Time
last_commit_time_v := time.parse(ts_v) or { panic(err) } last_commit_time_v := time.parse(ts_v) or { panic(err.msg) }
last_commit_time_vc := time.parse(ts_vc) or { panic(err) } last_commit_time_vc := time.parse(ts_vc) or { panic(err.msg) }
// git dates are in users local timezone and v time.parse does not parse // git dates are in users local timezone and v time.parse does not parse
// timezones at the moment, so for now get unix timestamp from output also // timezones at the moment, so for now get unix timestamp from output also
t_unix_v := git_log_v.find_between('Date Unix:', '\n').trim_space().int() t_unix_v := git_log_v.find_between('Date Unix:', '\n').trim_space().int()
@ -320,7 +320,7 @@ fn (mut gen_vc GenVC) command_execute(cmd string, dry bool) string {
gen_vc.logger.info('cmd: $cmd') gen_vc.logger.info('cmd: $cmd')
r := os.exec(cmd) or { r := os.exec(cmd) or {
gen_vc.logger.error('$err_msg_cmd_x: "$cmd" could not start.') gen_vc.logger.error('$err_msg_cmd_x: "$cmd" could not start.')
gen_vc.logger.error(err) gen_vc.logger.error(err.msg)
// something went wrong, better start fresh next time // something went wrong, better start fresh next time
gen_vc.purge_repos() gen_vc.purge_repos()
gen_vc.gen_error = true gen_vc.gen_error = true

View File

@ -55,7 +55,7 @@ fn report_undocumented_functions_in_path(opt Options, path string) {
} }
fn report_undocumented_functions_in_file(opt Options, file string) { fn report_undocumented_functions_in_file(opt Options, file string) {
contents := os.read_file(file) or { panic(err) } contents := os.read_file(file) or { panic(err.msg) }
lines := contents.split('\n') lines := contents.split('\n')
mut info := []UndocumentedFN{} mut info := []UndocumentedFN{}
for i, line in lines { for i, line in lines {

View File

@ -53,9 +53,9 @@ pub fn rmrf(path string) {
verbose_trace(@FN, 'rm -rf $path') verbose_trace(@FN, 'rm -rf $path')
if os.exists(path) { if os.exists(path) {
if os.is_dir(path) { if os.is_dir(path) {
os.rmdir_all(path) or { panic(err) } os.rmdir_all(path) or { panic(err.msg) }
} else { } else {
os.rm(path) or { panic(err) } os.rm(path) or { panic(err.msg) }
} }
} }
} }
@ -64,7 +64,7 @@ pub fn exec(cmd string) ?os.Result {
verbose_trace(@FN, cmd) verbose_trace(@FN, cmd)
x := os.exec(cmd) or { x := os.exec(cmd) or {
verbose_trace(@FN, '## failed.') verbose_trace(@FN, '## failed.')
return error(err) return err
} }
verbose_trace_exec_result(x) verbose_trace_exec_result(x)
return x return x

View File

@ -221,7 +221,7 @@ pub fn (mut ts TestSession) test() {
// cleanup generated .tmp.c files after successfull tests: // cleanup generated .tmp.c files after successfull tests:
if ts.benchmark.nfail == 0 { if ts.benchmark.nfail == 0 {
if ts.rm_binaries { if ts.rm_binaries {
os.rmdir_all(ts.vtmp_dir) or { panic(err) } os.rmdir_all(ts.vtmp_dir) or { panic(err.msg) }
} }
} }
} }
@ -255,7 +255,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
generated_binary_fpath := os.join_path(tmpd, generated_binary_fname) generated_binary_fpath := os.join_path(tmpd, generated_binary_fname)
if os.exists(generated_binary_fpath) { if os.exists(generated_binary_fpath) {
if ts.rm_binaries { if ts.rm_binaries {
os.rm(generated_binary_fpath) or { panic(err) } os.rm(generated_binary_fpath) or { panic(err.msg) }
} }
} }
mut cmd_options := [ts.vargs] mut cmd_options := [ts.vargs]
@ -308,7 +308,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr {
} }
if os.exists(generated_binary_fpath) { if os.exists(generated_binary_fpath) {
if ts.rm_binaries { if ts.rm_binaries {
os.rm(generated_binary_fpath) or { panic(err) } os.rm(generated_binary_fpath) or { panic(err.msg) }
} }
} }
return pool.no_result return pool.no_result
@ -358,7 +358,7 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main
continue continue
} }
} }
c := os.read_file(f) or { panic(err) } c := os.read_file(f) or { panic(err.msg) }
maxc := if c.len > 300 { 300 } else { c.len } maxc := if c.len > 300 { 300 } else { c.len }
start := c[0..maxc] start := c[0..maxc]
if start.contains('module ') && !start.contains('module main') { if start.contains('module ') && !start.contains('module main') {
@ -436,7 +436,7 @@ pub fn header(msg string) {
pub fn setup_new_vtmp_folder() string { pub fn setup_new_vtmp_folder() string {
now := time.sys_mono_now() now := time.sys_mono_now()
new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'test_session_$now') new_vtmp_dir := os.join_path(os.temp_dir(), 'v', 'test_session_$now')
os.mkdir_all(new_vtmp_dir) or { panic(err) } os.mkdir_all(new_vtmp_dir) or { panic(err.msg) }
os.setenv('VTMP', new_vtmp_dir, true) os.setenv('VTMP', new_vtmp_dir, true)
return new_vtmp_dir return new_vtmp_dir
} }

View File

@ -101,7 +101,7 @@ fn main() {
scripting.cprintln('# checkout folder: $context.path_v') scripting.cprintln('# checkout folder: $context.path_v')
if context.cmd_to_run.len > 0 { if context.cmd_to_run.len > 0 {
cmdres := os.exec(context.cmd_to_run) or { cmdres := os.exec(context.cmd_to_run) or {
panic(err) panic(err.msg)
} }
scripting.cprintln('# command: ${context.cmd_to_run:-34s} exit code: ${cmdres.exit_code:-4d} result:') scripting.cprintln('# command: ${context.cmd_to_run:-34s} exit code: ${cmdres.exit_code:-4d} result:')
println(cmdres.output) println(cmdres.output)

View File

@ -28,16 +28,16 @@ fn get_vexe_path() string {
fn new_tdir() string { fn new_tdir() string {
tdir_ := os.join_path(os.temp_dir(), rand.ulid()) tdir_ := os.join_path(os.temp_dir(), rand.ulid())
if os.exists(tdir_) { if os.exists(tdir_) {
os.rmdir(tdir_) or { panic(err) } os.rmdir(tdir_) or { panic(err.msg) }
} }
os.mkdir(tdir_) or { panic(err) } os.mkdir(tdir_) or { panic(err.msg) }
C.atexit(cleanup_tdir) C.atexit(cleanup_tdir)
return tdir_ return tdir_
} }
fn cleanup_tdir() { fn cleanup_tdir() {
println('... removing tdir: $tdir') println('... removing tdir: $tdir')
os.rmdir_all(tdir) or { panic(err) } os.rmdir_all(tdir) or { panic(err.msg) }
} }
fn main() { fn main() {
@ -55,7 +55,7 @@ fn main() {
fn check_ok(cmd string) string { fn check_ok(cmd string) string {
println('> check_ok cmd: $cmd') println('> check_ok cmd: $cmd')
res := os.exec(cmd) or { panic(err) } res := os.exec(cmd) or { panic(err.msg) }
if res.exit_code != 0 { if res.exit_code != 0 {
eprintln('> check_ok failed.\n$res.output') eprintln('> check_ok failed.\n$res.output')
exit(1) exit(1)
@ -65,7 +65,7 @@ fn check_ok(cmd string) string {
fn check_fail(cmd string) string { fn check_fail(cmd string) string {
println('> check_fail cmd: $cmd') println('> check_fail cmd: $cmd')
res := os.exec(cmd) or { panic(err) } res := os.exec(cmd) or { panic(err.msg) }
if res.exit_code == 0 { if res.exit_code == 0 {
eprintln('> check_fail succeeded, but it should have failed.\n$res.output') eprintln('> check_fail succeeded, but it should have failed.\n$res.output')
exit(1) exit(1)

View File

@ -108,7 +108,7 @@ fn main() {
exit(0) exit(0)
} }
files := fp.finalize() or { files := fp.finalize() or {
eprintln('Error: ' + err) eprintln('Error: $err')
exit(1) exit(1)
} }
real_files := files.filter(it != 'bin2v') real_files := files.filter(it != 'bin2v')

View File

@ -55,11 +55,11 @@ fn main() {
// //
tpath := os.join_path(session.vtmp_dir, texe) tpath := os.join_path(session.vtmp_dir, texe)
if tname in tools_in_subfolders { if tname in tools_in_subfolders {
os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err) } os.mv_by_cp(tpath, os.join_path(tfolder, tname, texe)) or { panic(err.msg) }
continue continue
} }
os.mv_by_cp(tpath, os.join_path(tfolder, texe)) or { os.mv_by_cp(tpath, os.join_path(tfolder, texe)) or {
if !err.contains('vbuild-tools') { if !err.msg.contains('vbuild-tools') {
eprintln(err) eprintln(err)
} }
continue continue

View File

@ -244,7 +244,7 @@ fn (mut f MDFile) check_examples() (int, int) {
mut should_cleanup_vfile := true mut should_cleanup_vfile := true
// eprintln('>>> checking example $vfile ...') // eprintln('>>> checking example $vfile ...')
vcontent := e.text.join('\n') + '\n' vcontent := e.text.join('\n') + '\n'
os.write_file(vfile, vcontent) or { panic(err) } os.write_file(vfile, vcontent) or { panic(err.msg) }
mut acommands := e.command.split(' ') mut acommands := e.command.split(' ')
nofmt := 'nofmt' in acommands nofmt := 'nofmt' in acommands
for command in acommands { for command in acommands {
@ -331,7 +331,7 @@ fn (mut f MDFile) check_examples() (int, int) {
} }
} }
if should_cleanup_vfile { if should_cleanup_vfile {
os.rm(vfile) or { panic(err) } os.rm(vfile) or { panic(err.msg) }
} }
} }
return errors, oks return errors, oks

View File

@ -55,10 +55,10 @@ fn gen_gitignore(name string) string {
fn (c &Create) write_vmod(new bool) { fn (c &Create) write_vmod(new bool) {
vmod_path := if new { '$c.name/v.mod' } else { 'v.mod' } vmod_path := if new { '$c.name/v.mod' } else { 'v.mod' }
mut vmod := os.create(vmod_path) or { mut vmod := os.create(vmod_path) or {
cerror(err) cerror(err.msg)
exit(1) exit(1)
} }
vmod.write_str(vmod_content(c.name, c.description)) or { panic(err) } vmod.write_str(vmod_content(c.name, c.description)) or { panic(err.msg) }
vmod.close() vmod.close()
} }
@ -68,10 +68,10 @@ fn (c &Create) write_main(new bool) {
} }
main_path := if new { '$c.name/${c.name}.v' } else { '${c.name}.v' } main_path := if new { '$c.name/${c.name}.v' } else { '${c.name}.v' }
mut mainfile := os.create(main_path) or { mut mainfile := os.create(main_path) or {
cerror(err) cerror(err.msg)
exit(2) exit(2)
} }
mainfile.write_str(main_content()) or { panic(err) } mainfile.write_str(main_content()) or { panic(err.msg) }
mainfile.close() mainfile.close()
} }
@ -87,7 +87,7 @@ fn (c &Create) create_git_repo(dir string) {
// We don't really need a .gitignore, it's just a nice-to-have // We don't really need a .gitignore, it's just a nice-to-have
return return
} }
fl.write_str(gen_gitignore(c.name)) or { panic(err) } fl.write_str(gen_gitignore(c.name)) or { panic(err.msg) }
fl.close() fl.close()
} }
} }
@ -110,7 +110,7 @@ fn create() {
} }
c.description = os.input('Input your project description: ') c.description = os.input('Input your project description: ')
println('Initialising ...') println('Initialising ...')
os.mkdir(c.name) or { panic(err) } os.mkdir(c.name) or { panic(err.msg) }
c.write_vmod(true) c.write_vmod(true)
c.write_main(true) c.write_main(true)
c.create_git_repo(c.name) c.create_git_repo(c.name)

View File

@ -126,7 +126,7 @@ fn (vd VDoc) render_search_index(out Output) {
js_search_index.writeln('];') js_search_index.writeln('];')
js_search_data.writeln('];') js_search_data.writeln('];')
out_file_path := os.join_path(out.path, 'search_index.js') out_file_path := os.join_path(out.path, 'search_index.js')
os.write_file(out_file_path, js_search_index.str() + js_search_data.str()) or { panic(err) } os.write_file(out_file_path, js_search_index.str() + js_search_data.str()) or { panic(err.msg) }
} }
fn (mut vd VDoc) render_static_html(out Output) { fn (mut vd VDoc) render_static_html(out Output) {
@ -162,7 +162,7 @@ fn (vd VDoc) get_resource(name string, out Output) string {
output_path := os.join_path(out.path, name) output_path := os.join_path(out.path, name)
if !os.exists(output_path) { if !os.exists(output_path) {
println('Generating $out.typ in "$output_path"') println('Generating $out.typ in "$output_path"')
os.write_file(output_path, res) or { panic(err) } os.write_file(output_path, res) or { panic(err.msg) }
} }
return name return name
} }

View File

@ -162,7 +162,7 @@ fn (vd VDoc) work_processor(mut work sync.Channel, mut wg sync.WaitGroup) {
file_name, content := vd.render_doc(pdoc.d, pdoc.out) file_name, content := vd.render_doc(pdoc.d, pdoc.out)
output_path := os.join_path(pdoc.out.path, file_name) output_path := os.join_path(pdoc.out.path, file_name)
println('Generating $pdoc.out.typ in "$output_path"') println('Generating $pdoc.out.typ in "$output_path"')
os.write_file(output_path, content) or { panic(err) } os.write_file(output_path, content) or { panic(err.msg) }
} }
wg.done() wg.done()
} }
@ -350,15 +350,15 @@ fn (mut vd VDoc) generate_docs_from_file() {
out.path = os.real_path('.') out.path = os.real_path('.')
} }
if !os.exists(out.path) { if !os.exists(out.path) {
os.mkdir(out.path) or { panic(err) } os.mkdir(out.path) or { panic(err.msg) }
} }
if cfg.is_multi { if cfg.is_multi {
out.path = os.join_path(out.path, '_docs') out.path = os.join_path(out.path, '_docs')
if !os.exists(out.path) { if !os.exists(out.path) {
os.mkdir(out.path) or { panic(err) } os.mkdir(out.path) or { panic(err.msg) }
} else { } else {
for fname in css_js_assets { for fname in css_js_assets {
os.rm(os.join_path(out.path, fname)) or { panic(err) } os.rm(os.join_path(out.path, fname)) or { panic(err.msg) }
} }
} }
} }
@ -372,11 +372,11 @@ fn (mut vd VDoc) generate_docs_from_file() {
vd.render_search_index(out) vd.render_search_index(out)
// move favicons to target directory // move favicons to target directory
println('Copying favicons...') println('Copying favicons...')
favicons := os.ls(favicons_path) or { panic(err) } favicons := os.ls(favicons_path) or { panic(err.msg) }
for favicon in favicons { for favicon in favicons {
favicon_path := os.join_path(favicons_path, favicon) favicon_path := os.join_path(favicons_path, favicon)
destination_path := os.join_path(out.path, favicon) destination_path := os.join_path(out.path, favicon)
os.cp(favicon_path, destination_path) or { panic(err) } os.cp(favicon_path, destination_path) or { panic(err.msg) }
} }
} }
} }

View File

@ -175,7 +175,7 @@ fn (foptions &FormatOptions) format_file(file string) {
file_name := os.file_name(file) file_name := os.file_name(file)
ulid := rand.ulid() ulid := rand.ulid()
vfmt_output_path := os.join_path(vtmp_folder, 'vfmt_${ulid}_$file_name') vfmt_output_path := os.join_path(vtmp_folder, 'vfmt_${ulid}_$file_name')
os.write_file(vfmt_output_path, formatted_content) or { panic(err) } os.write_file(vfmt_output_path, formatted_content) or { panic(err.msg) }
if foptions.is_verbose { if foptions.is_verbose {
eprintln('fmt.fmt worked and $formatted_content.len bytes were written to $vfmt_output_path .') eprintln('fmt.fmt worked and $formatted_content.len bytes were written to $vfmt_output_path .')
} }
@ -266,7 +266,7 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
} }
if foptions.is_w { if foptions.is_w {
if is_formatted_different { if is_formatted_different {
os.mv_by_cp(formatted_file_path, file) or { panic(err) } os.mv_by_cp(formatted_file_path, file) or { panic(err.msg) }
eprintln('Reformatted file: $file') eprintln('Reformatted file: $file')
} else { } else {
eprintln('Already formatted file: $file') eprintln('Already formatted file: $file')
@ -312,7 +312,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
pfolder := os.real_path(os.dir(file)) pfolder := os.real_path(os.dir(file))
// a .v project has many 'module main' files in one folder // a .v project has many 'module main' files in one folder
// if there is only one .v file, then it must be a standalone // if there is only one .v file, then it must be a standalone
all_files_in_pfolder := os.ls(pfolder) or { panic(err) } all_files_in_pfolder := os.ls(pfolder) or { panic(err.msg) }
mut vfiles := []string{} mut vfiles := []string{}
for f in all_files_in_pfolder { for f in all_files_in_pfolder {
vf := os.join_path(pfolder, f) vf := os.join_path(pfolder, f)
@ -332,7 +332,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
// a project folder, that should be compiled with `v pfolder`. // a project folder, that should be compiled with `v pfolder`.
mut main_fns := 0 mut main_fns := 0
for f in vfiles { for f in vfiles {
slines := read_source_lines(f) or { panic(err) } slines := read_source_lines(f) or { panic(err.msg) }
for line in slines { for line in slines {
if line.contains('fn main()') { if line.contains('fn main()') {
main_fns++ main_fns++

View File

@ -71,7 +71,7 @@ fn main() {
'install' { 'install' {
if module_names.len == 0 && os.exists('./v.mod') { if module_names.len == 0 && os.exists('./v.mod') {
println('Detected v.mod file inside the project directory. Using it...') println('Detected v.mod file inside the project directory. Using it...')
manifest := vmod.from_file('./v.mod') or { panic(err) } manifest := vmod.from_file('./v.mod') or { panic(err.msg) }
module_names = manifest.dependencies module_names = manifest.dependencies
} }
vpm_install(module_names) vpm_install(module_names)
@ -331,13 +331,13 @@ fn vpm_remove(module_names []string) {
final_module_path := valid_final_path_of_existing_module(name) or { continue } final_module_path := valid_final_path_of_existing_module(name) or { continue }
println('Removing module "$name"...') println('Removing module "$name"...')
verbose_println('removing folder $final_module_path') verbose_println('removing folder $final_module_path')
os.rmdir_all(final_module_path) or { panic(err) } os.rmdir_all(final_module_path) or { panic(err.msg) }
// delete author directory if it is empty // delete author directory if it is empty
author := name.split('.')[0] author := name.split('.')[0]
author_dir := os.real_path(os.join_path(settings.vmodules_path, author)) author_dir := os.real_path(os.join_path(settings.vmodules_path, author))
if os.is_dir_empty(author_dir) { if os.is_dir_empty(author_dir) {
verbose_println('removing author folder $author_dir') verbose_println('removing author folder $author_dir')
os.rmdir(author_dir) or { panic(err) } os.rmdir(author_dir) or { panic(err.msg) }
} }
} }
} }
@ -364,7 +364,7 @@ fn valid_final_path_of_existing_module(name string) ?string {
fn ensure_vmodules_dir_exist() { fn ensure_vmodules_dir_exist() {
if !os.is_dir(settings.vmodules_path) { if !os.is_dir(settings.vmodules_path) {
println('Creating $settings.vmodules_path/ ...') println('Creating $settings.vmodules_path/ ...')
os.mkdir(settings.vmodules_path) or { panic(err) } os.mkdir(settings.vmodules_path) or { panic(err.msg) }
} }
} }
@ -411,7 +411,7 @@ fn get_installed_modules() []string {
fn get_all_modules() []string { fn get_all_modules() []string {
url := get_working_server_url() url := get_working_server_url()
r := http.get(url) or { panic(err) } r := http.get(url) or { panic(err.msg) }
if r.status_code != 200 { if r.status_code != 200 {
println('Failed to search vpm.vlang.io. Status code: $r.status_code') println('Failed to search vpm.vlang.io. Status code: $r.status_code')
exit(1) exit(1)

View File

@ -184,7 +184,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
} }
if r.line.starts_with('print') { if r.line.starts_with('print') {
source_code := r.current_source_code(false) + '\n$r.line\n' source_code := r.current_source_code(false) + '\n$r.line\n'
os.write_file(file, source_code) or { panic(err) } os.write_file(file, source_code) or { panic(err.msg) }
s := repl_run_vfile(file) or { return } s := repl_run_vfile(file) or { return }
print_output(s) print_output(s)
} else { } else {
@ -251,7 +251,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
} }
temp_source_code = r.current_source_code(true) + '\n$temp_line\n' temp_source_code = r.current_source_code(true) + '\n$temp_line\n'
} }
os.write_file(temp_file, temp_source_code) or { panic(err) } os.write_file(temp_file, temp_source_code) or { panic(err.msg) }
s := repl_run_vfile(temp_file) or { return } s := repl_run_vfile(temp_file) or { return }
if !func_call && s.exit_code == 0 && !temp_flag { if !func_call && s.exit_code == 0 && !temp_flag {
for r.temp_lines.len > 0 { for r.temp_lines.len > 0 {
@ -355,8 +355,8 @@ fn repl_run_vfile(file string) ?os.Result {
eprintln('>> repl_run_vfile file: $file') eprintln('>> repl_run_vfile file: $file')
} }
s := os.exec('"$vexe" -repl run "$file"') or { s := os.exec('"$vexe" -repl run "$file"') or {
rerror(err) rerror(err.msg)
return error(err) return err
} }
return s return s
} }

View File

@ -27,12 +27,12 @@ fn main() {
// The user just wants an independent copy of v, and so we are done. // The user just wants an independent copy of v, and so we are done.
return return
} }
backup_old_version_and_rename_newer() or { panic(err) } backup_old_version_and_rename_newer() or { panic(err.msg) }
println('V built successfully!') println('V built successfully!')
} }
fn compile(vroot string, cmd string) { fn compile(vroot string, cmd string) {
result := os.exec(cmd) or { panic(err) } result := os.exec(cmd) or { panic(err.msg) }
if result.exit_code != 0 { if result.exit_code != 0 {
eprintln('cannot compile to `$vroot`: \n$result.output') eprintln('cannot compile to `$vroot`: \n$result.output')
exit(1) exit(1)
@ -76,7 +76,7 @@ fn backup_old_version_and_rename_newer() ?bool {
os.rm(v_file) or { } os.rm(v_file) or { }
list_folder('', 'moving $v2_file to $v_file ...') list_folder('', 'moving $v2_file to $v_file ...')
os.mv_by_cp(v2_file, v_file) or { panic(err) } os.mv_by_cp(v2_file, v_file) or { panic(err.msg) }
list_folder('after:', '') list_folder('after:', '')

View File

@ -12,7 +12,7 @@ fn main() {
println('Thirdparty "freetype" is already installed.') println('Thirdparty "freetype" is already installed.')
} else { } else {
s := os.exec('git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries ./thirdparty/freetype/') or { s := os.exec('git clone --depth=1 https://github.com/ubawurinna/freetype-windows-binaries ./thirdparty/freetype/') or {
panic(err) panic(err.msg)
} }
println(s.output) println(s.output)
println('Thirdparty "freetype" installed successfully.') println('Thirdparty "freetype" installed successfully.')

View File

@ -27,11 +27,11 @@ fn setup_symlink_unix(vexe string) {
if os.system("uname -o | grep -q '[A/a]ndroid'") == 1 { if os.system("uname -o | grep -q '[A/a]ndroid'") == 1 {
link_dir := '/usr/local/bin' link_dir := '/usr/local/bin'
if !os.exists(link_dir) { if !os.exists(link_dir) {
os.mkdir_all(link_dir) or { panic(err) } os.mkdir_all(link_dir) or { panic(err.msg) }
} }
link_path = link_dir + '/v' link_path = link_dir + '/v'
} }
ret := os.exec('ln -sf $vexe $link_path') or { panic(err) } ret := os.exec('ln -sf $vexe $link_path') or { panic(err.msg) }
if ret.exit_code == 0 { if ret.exit_code == 0 {
println('Symlink "$link_path" has been created') println('Symlink "$link_path" has been created')
} else { } else {
@ -49,14 +49,14 @@ fn setup_symlink_windows(vexe string) {
mut vsymlink := os.join_path(vsymlinkdir, 'v.exe') mut vsymlink := os.join_path(vsymlinkdir, 'v.exe')
// Remove old symlink first (v could have been moved, symlink rerun) // Remove old symlink first (v could have been moved, symlink rerun)
if !os.exists(vsymlinkdir) { if !os.exists(vsymlinkdir) {
os.mkdir(vsymlinkdir) or { panic(err) } os.mkdir(vsymlinkdir) or { panic(err.msg) }
} else { } else {
if os.exists(vsymlink) { if os.exists(vsymlink) {
os.rm(vsymlink) or { panic(err) } os.rm(vsymlink) or { panic(err.msg) }
} else { } else {
vsymlink = os.join_path(vsymlinkdir, 'v.bat') vsymlink = os.join_path(vsymlinkdir, 'v.bat')
if os.exists(vsymlink) { if os.exists(vsymlink) {
os.rm(vsymlink) or { panic(err) } os.rm(vsymlink) or { panic(err.msg) }
} }
vsymlink = os.join_path(vsymlinkdir, 'v.exe') vsymlink = os.join_path(vsymlinkdir, 'v.exe')
} }
@ -69,9 +69,9 @@ fn setup_symlink_windows(vexe string) {
eprintln('Creating a batch file instead...') eprintln('Creating a batch file instead...')
vsymlink = os.join_path(vsymlinkdir, 'v.bat') vsymlink = os.join_path(vsymlinkdir, 'v.bat')
if os.exists(vsymlink) { if os.exists(vsymlink) {
os.rm(vsymlink) or { panic(err) } os.rm(vsymlink) or { panic(err.msg) }
} }
os.write_file(vsymlink, '@echo off\n$vexe %*') or { panic(err) } os.write_file(vsymlink, '@echo off\n$vexe %*') or { panic(err.msg) }
eprintln('$vsymlink file written.') eprintln('$vsymlink file written.')
} }
if !os.exists(vsymlink) { if !os.exists(vsymlink) {
@ -80,7 +80,7 @@ fn setup_symlink_windows(vexe string) {
println('Symlink $vsymlink to $vexe created.') println('Symlink $vsymlink to $vexe created.')
println('Checking system %PATH%...') println('Checking system %PATH%...')
reg_sys_env_handle := get_reg_sys_env_handle() or { reg_sys_env_handle := get_reg_sys_env_handle() or {
warn_and_exit(err) warn_and_exit(err.msg)
return return
} }
// TODO: Fix defers inside ifs // TODO: Fix defers inside ifs
@ -107,7 +107,7 @@ fn setup_symlink_windows(vexe string) {
println('Adding symlink directory to system %PATH%...') println('Adding symlink directory to system %PATH%...')
set_reg_value(reg_sys_env_handle, 'Path', new_sys_env_path) or { set_reg_value(reg_sys_env_handle, 'Path', new_sys_env_path) or {
C.RegCloseKey(reg_sys_env_handle) C.RegCloseKey(reg_sys_env_handle)
warn_and_exit(err) warn_and_exit(err.msg)
} }
println('Done.') println('Done.')
} }

View File

@ -124,7 +124,7 @@ fn process_cli_args() &Context {
exit(0) exit(0)
} }
context.all_paths = fp.finalize() or { context.all_paths = fp.finalize() or {
context.error(err) context.error(err.msg)
exit(1) exit(1)
} }
if !context.is_worker && context.all_paths.len == 0 { if !context.is_worker && context.all_paths.len == 0 {
@ -218,7 +218,7 @@ fn (mut context Context) process_whole_file_in_worker(path string) (int, int) {
cmd := '"$context.myself" $verbosity --worker --timeout_ms ${context.timeout_ms:5} --cut_index ${i:5} --path "$path" ' cmd := '"$context.myself" $verbosity --worker --timeout_ms ${context.timeout_ms:5} --cut_index ${i:5} --path "$path" '
context.log(cmd) context.log(cmd)
res := os.exec(cmd) or { os.Result{ res := os.exec(cmd) or { os.Result{
output: err output: err.msg
exit_code: ecode_exec exit_code: ecode_exec
} } } }
context.log('worker exit_code: $res.exit_code | worker output:\n$res.output') context.log('worker exit_code: $res.exit_code | worker output:\n$res.output')

View File

@ -41,7 +41,7 @@ fn main() {
app.backup('cmd/tools/vup.exe') app.backup('cmd/tools/vup.exe')
} }
app.recompile_v() app.recompile_v()
os.exec('"$app.vexe" cmd/tools/vup.v') or { panic(err) } os.exec('"$app.vexe" cmd/tools/vup.v') or { panic(err.msg) }
app.show_current_v_version() app.show_current_v_version()
} }
@ -88,7 +88,7 @@ fn (app App) make(vself string) {
$if windows { $if windows {
make = 'make.bat' make = 'make.bat'
} }
make_result := os.exec(make) or { panic(err) } make_result := os.exec(make) or { panic(err.msg) }
app.vprintln(make_result.output) app.vprintln(make_result.output)
} }
@ -121,7 +121,7 @@ fn (app App) git_command(command string) {
git_result := os.exec('git $command') or { git_result := os.exec('git $command') or {
app.get_git() app.get_git()
// Try it again with (maybe) git installed // Try it again with (maybe) git installed
os.exec('git $command') or { panic(err) } os.exec('git $command') or { panic(err.msg) }
} }
if git_result.exit_code != 0 { if git_result.exit_code != 0 {
eprintln(git_result.output) eprintln(git_result.output)
@ -136,11 +136,11 @@ fn (app App) get_git() {
// We'll use 32 bit because maybe someone out there is using 32-bit windows // We'll use 32 bit because maybe someone out there is using 32-bit windows
os.exec('bitsadmin.exe /transfer "vgit" https://github.com/git-for-windows/git/releases/download/v2.30.0.windows.2/Git-2.30.0.2-32-bit.exe "$os.getwd()/git32.exe"') or { os.exec('bitsadmin.exe /transfer "vgit" https://github.com/git-for-windows/git/releases/download/v2.30.0.windows.2/Git-2.30.0.2-32-bit.exe "$os.getwd()/git32.exe"') or {
eprintln('Unable to install git automatically: please install git manually') eprintln('Unable to install git automatically: please install git manually')
panic(err) panic(err.msg)
} }
os.exec('$os.getwd()/git32.exe') or { os.exec('$os.getwd()/git32.exe') or {
eprintln('Unable to install git automatically: please install git manually') eprintln('Unable to install git automatically: please install git manually')
panic(err) panic(err.msg)
} }
} $else { // Probably some kind of *nix, usually need to get using a package manager. } $else { // Probably some kind of *nix, usually need to get using a package manager.
eprintln("error: Install `git` using your system's package manager") eprintln("error: Install `git` using your system's package manager")

View File

@ -21,7 +21,7 @@ fn test_vet() {
} }
fn get_tests_in_dir(dir string) []string { fn get_tests_in_dir(dir string) []string {
files := os.ls(dir) or { panic(err) } files := os.ls(dir) or { panic(err.msg) }
mut tests := files.filter(it.ends_with('.vv')) mut tests := files.filter(it.ends_with('.vv'))
tests.sort() tests.sort()
return tests return tests
@ -34,8 +34,8 @@ fn check_path(vexe string, dir string, tests []string) int {
program := path program := path
print(path + ' ') print(path + ' ')
// -force is needed so that `v vet` would not skip the regression files // -force is needed so that `v vet` would not skip the regression files
res := os.exec('$vexe vet -force $program') or { panic(err) } res := os.exec('$vexe vet -force $program') or { panic(err.msg) }
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err) } mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err.msg) }
expected = clean_line_endings(expected) expected = clean_line_endings(expected)
found := clean_line_endings(res.output) found := clean_line_endings(res.output)
if expected != found { if expected != found {

View File

@ -1321,7 +1321,7 @@ import os
fn read_log() { fn read_log() {
mut ok := false mut ok := false
mut f := os.open('log.txt') or { panic(err) } mut f := os.open('log.txt') or { panic(err.msg) }
defer { defer {
f.close() f.close()
} }
@ -2401,7 +2401,7 @@ any further.
The body of `f` is essentially a condensed version of: The body of `f` is essentially a condensed version of:
```v ignore ```v ignore
resp := http.get(url) or { return error(err) } resp := http.get(url) or { return err }
return resp.text return resp.text
``` ```
@ -2418,7 +2418,7 @@ to break from the current block.
Note that `break` and `continue` can only be used inside a `for` loop. Note that `break` and `continue` can only be used inside a `for` loop.
V does not have a way to forcibly "unwrap" an optional (as other languages do, V does not have a way to forcibly "unwrap" an optional (as other languages do,
for instance Rust's `unwrap()` or Swift's `!`). To do this, use `or { panic(err) }` instead. for instance Rust's `unwrap()` or Swift's `!`). To do this, use `or { panic(err.msg) }` instead.
--- ---
The third method is to provide a default value at the end of the `or` block. The third method is to provide a default value at the end of the `or` block.
@ -3495,7 +3495,7 @@ Full list of builtin options:
module main module main
fn main() { fn main() {
embedded_file := $embed_file('v.png') embedded_file := $embed_file('v.png')
mut fw := os.create('exported.png') or { panic(err) } mut fw := os.create('exported.png') or { panic(err.msg) }
fw.write_bytes(embedded_file.data(), embedded_file.len) fw.write_bytes(embedded_file.data(), embedded_file.len)
fw.close() fw.close()
} }
@ -3658,7 +3658,7 @@ eprintln('file: ' + @FILE + ' | line: ' + @LINE + ' | fn: ' + @MOD + '.' + @FN)
Another example, is if you want to embed the version/name from v.mod *inside* your executable: Another example, is if you want to embed the version/name from v.mod *inside* your executable:
```v ignore ```v ignore
import v.vmod import v.vmod
vm := vmod.decode( @VMOD_FILE ) or { panic(err) } vm := vmod.decode( @VMOD_FILE ) or { panic(err.msg) }
eprintln('$vm.name $vm.version\n $vm.description') eprintln('$vm.name $vm.version\n $vm.description')
``` ```

View File

@ -16,7 +16,7 @@ struct User {
} }
fn main() { fn main() {
db := sqlite.connect(':memory:') or { panic(err) } db := sqlite.connect(':memory:') or { panic(err.msg) }
db.exec('drop table if exists User') 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 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);") db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")

View File

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

View File

@ -212,13 +212,13 @@ fn (mut app App) run() {
fn init_images(mut app App) { fn init_images(mut app App) {
$if android { $if android {
background := os.read_apk_asset('img/background.png') or { panic(err) } background := os.read_apk_asset('img/background.png') or { panic(err.msg) }
app.background = app.gg.create_image_from_byte_array(background) app.background = app.gg.create_image_from_byte_array(background)
bird := os.read_apk_asset('img/bird.png') or { panic(err) } bird := os.read_apk_asset('img/bird.png') or { panic(err.msg) }
app.bird = app.gg.create_image_from_byte_array(bird) app.bird = app.gg.create_image_from_byte_array(bird)
pipetop := os.read_apk_asset('img/pipetop.png') or { panic(err) } pipetop := os.read_apk_asset('img/pipetop.png') or { panic(err.msg) }
app.pipetop = app.gg.create_image_from_byte_array(pipetop) app.pipetop = app.gg.create_image_from_byte_array(pipetop)
pipebottom := os.read_apk_asset('img/pipebottom.png') or { panic(err) } pipebottom := os.read_apk_asset('img/pipebottom.png') or { panic(err.msg) }
app.pipebottom = app.gg.create_image_from_byte_array(pipebottom) app.pipebottom = app.gg.create_image_from_byte_array(pipebottom)
} $else { } $else {
app.background = app.gg.create_image(os.resource_abs_path('assets/img/background.png')) 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 // write out a .ppm file
fn (image Image) save_as_ppm(file_name string) { fn (image Image) save_as_ppm(file_name string) {
npixels := image.width * image.height npixels := image.width * image.height
mut f_out := os.create(file_name) or { panic(err) } mut f_out := os.create(file_name) or { panic(err.msg) }
f_out.writeln('P3') or { panic(err) } f_out.writeln('P3') or { panic(err.msg) }
f_out.writeln('$image.width $image.height') or { panic(err) } f_out.writeln('$image.width $image.height') or { panic(err.msg) }
f_out.writeln('255') or { panic(err) } f_out.writeln('255') or { panic(err.msg) }
for i in 0 .. npixels { for i in 0 .. npixels {
c_r := to_int(unsafe { image.data[i] }.x) c_r := to_int(unsafe { image.data[i] }.x)
c_g := to_int(unsafe { image.data[i] }.y) c_g := to_int(unsafe { image.data[i] }.y)
c_b := to_int(unsafe { image.data[i] }.z) c_b := to_int(unsafe { image.data[i] }.z)
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() f_out.close()
} }

View File

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

View File

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

View File

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

View File

@ -20,12 +20,12 @@ fn convert_html_rgb(in_col string) u32 {
mut col_mul := if in_col.len == 4 { 4 } else { 0 } mut col_mul := if in_col.len == 4 { 4 } else { 0 }
// this is the regex query, it uses V string interpolation to customize the regex query // this is the regex query, it uses V string interpolation to customize the regex query
// NOTE: if you want use escaped code you must use the r"" (raw) strings, // NOTE: if you want use escaped code you must use the r"" (raw) strings,
// *** please remember that V interpoaltion doesn't work on raw strings. *** // *** please remember that V interpoaltion doesn't work on raw strings. ***
query := '#([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})' 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) } mut re := regex.regex_opt(query) or { panic(err.msg) }
start, end := re.match_string(in_col) start, end := re.match_string(in_col)
println('start: $start, end: $end') println('start: $start, end: $end')
mut res := u32(0) 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})' 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) } mut re := regex.regex_opt(query) or { panic(err.msg) }
start, end := re.match_string(in_col) start, end := re.match_string(in_col)
println('start: $start, end: $end') println('start: $start, end: $end')
mut res := u32(0) mut res := u32(0)

View File

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

View File

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

View File

@ -135,7 +135,7 @@ fn main() {
// load TTF fonts // load TTF fonts
for font_path in font_paths { for font_path in font_paths {
mut tf := ttf.TTF_File{} mut tf := ttf.TTF_File{}
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') println('TrueTypeFont file [$font_path] len: $tf.buf.len')
tf.init() tf.init()
println('Unit per EM: $tf.units_per_em') println('Unit per EM: $tf.units_per_em')

View File

@ -12,14 +12,14 @@ mkdir('v_script_dir')
println("\nEntering into v_script_dir and listing it's files.") println("\nEntering into v_script_dir and listing it's files.")
chdir('v_script_dir') chdir('v_script_dir')
files := ls('.') or { panic(err) } files := ls('.') or { panic(err.msg) }
println(files) println(files)
println('\nCreating foo.txt') println('\nCreating foo.txt')
create('foo.txt')? create('foo.txt')?
println('\nFiles:') println('\nFiles:')
again_ls := ls('.') or { panic(err) } again_ls := ls('.') or { panic(err.msg) }
println(again_ls) println(again_ls)
println('\nRemoving foo.txt and v_script_dir') println('\nRemoving foo.txt and v_script_dir')

View File

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

View File

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

View File

@ -32,7 +32,7 @@ pub fn (app &App) index() vweb.Result {
} }
pub fn (mut app App) init_once() { pub fn (mut app App) init_once() {
app.db = sqlite.connect('blog.db') or { panic(err) } app.db = sqlite.connect('blog.db') or { panic(err.msg) }
app.db.exec('create table if not exists article (' + 'id integer primary key, ' + "title text default ''," + app.db.exec('create table if not exists article (' + 'id integer primary key, ' + "title text default ''," +
"text text default ''" + ');') "text text default ''" + ');')
} }

View File

@ -13,7 +13,7 @@ fn test_syscallwrappers() {
os.chdir(dot_checks) os.chdir(dot_checks)
checks_v := "checks.v" checks_v := "checks.v"
assert os.exists(checks_v) assert os.exists(checks_v)
rc := os.exec("v run $checks_v") or { panic(err) } rc := os.exec("v run $checks_v") or { panic(err.msg) }
assert !rc.output.contains("V panic: An assertion failed.") assert !rc.output.contains("V panic: An assertion failed.")
assert !rc.output.contains("failed") assert !rc.output.contains("failed")
assert rc.exit_code == 0 assert rc.exit_code == 0

View File

@ -44,8 +44,8 @@ pub fn exit(c int) {
pub fn unwrap(opt any) any { pub fn unwrap(opt any) any {
o := &Option(opt) o := &Option(opt)
if o.not_ok { if o.state != 0 {
js_throw(o.error) js_throw(o.err)
} }
return opt return opt
} }
@ -55,38 +55,44 @@ pub fn panic(s string) {
exit(1) exit(1)
} }
struct Option<T> {
state byte
err Error
data T
}
struct Option { pub struct Error {
not_ok bool pub:
is_none bool msg string
error string code int
ecode int
data any
} }
pub fn (o Option) str() string { pub fn (o Option) str() string {
if !o.not_ok { if o.state == 0 {
return 'Option{ ok }' return 'Option{ ok }'
} }
if o.is_none { if o.state == 1 {
return 'Option{ none }' return 'Option{ none }'
} }
return 'Option{ error: "${o.error}" }' return 'Option{ error: "${o.err}" }'
} }
pub fn error(s string) Option { pub fn error(s string) Option {
return Option{ return Option{
not_ok: true state: 2
is_none: false err: {
error: s msg: s
}
} }
} }
pub fn error_with_code(s string, code int) Option { pub fn error_with_code(s string, code int) Option {
return Option{ return Option{
not_ok: true state: 2
is_none: false err: {
error: s msg: s
ecode: code code: code
}
} }
} }

View File

@ -259,7 +259,7 @@ fn (cmd Command) check_version_flag() {
version_flag := cmd.flags.get_bool('version') or { return } // ignore error and handle command normally version_flag := cmd.flags.get_bool('version') or { return } // ignore error and handle command normally
if version_flag { if version_flag {
version_cmd := cmd.commands.get('version') or { return } // ignore error and handle command normally version_cmd := cmd.commands.get('version') or { return } // ignore error and handle command normally
version_cmd.execute(version_cmd) or { panic(err) } version_cmd.execute(version_cmd) or { panic(err.msg) }
exit(0) exit(0)
} }
} }
@ -280,7 +280,7 @@ fn (cmd Command) check_required_flags() {
pub fn (cmd Command) execute_help() { pub fn (cmd Command) execute_help() {
if cmd.commands.contains('help') { if cmd.commands.contains('help') {
help_cmd := cmd.commands.get('help') or { return } // ignore error and handle command normally help_cmd := cmd.commands.get('help') or { return } // ignore error and handle command normally
help_cmd.execute(help_cmd) or { panic(err) } help_cmd.execute(help_cmd) or { panic(err.msg) }
} else { } else {
print(cmd.help_message()) print(cmd.help_message())
} }

View File

@ -135,7 +135,7 @@ fn test_if_required_flags_get_set() {
} }
fn flag_is_set_in_subcommand(cmd cli.Command) ? { fn flag_is_set_in_subcommand(cmd cli.Command) ? {
flag := cmd.flags.get_string('flag') or { panic(err) } flag := cmd.flags.get_string('flag') or { panic(err.msg) }
assert flag == 'value' assert flag == 'value'
} }

View File

@ -5,16 +5,16 @@ fn test_if_string_flag_parses() {
flag: .string flag: .string
name: 'flag' name: 'flag'
} }
flag.parse(['-flag', 'value1'], false) or { panic(err) } flag.parse(['-flag', 'value1'], false) or { panic(err.msg) }
mut value := flag.get_string() or { panic(err) } mut value := flag.get_string() or { panic(err.msg) }
assert value == 'value1' assert value == 'value1'
flag = cli.Flag{ flag = cli.Flag{
flag: .string flag: .string
name: 'flag' name: 'flag'
} }
flag.parse(['-flag=value2'], false) or { panic(err) } flag.parse(['-flag=value2'], false) or { panic(err.msg) }
value = flag.get_string() or { panic(err) } value = flag.get_string() or { panic(err.msg) }
assert value == 'value2' assert value == 'value2'
flag = cli.Flag{ flag = cli.Flag{
@ -22,9 +22,9 @@ fn test_if_string_flag_parses() {
name: 'flag' name: 'flag'
multiple: true multiple: true
} }
flag.parse(['-flag=value1'], false) or { panic(err) } flag.parse(['-flag=value1'], false) or { panic(err.msg) }
flag.parse(['-flag=value2'], false) or { panic(err) } flag.parse(['-flag=value2'], false) or { panic(err.msg) }
mut values := flag.get_strings() or { panic(err) } mut values := flag.get_strings() or { panic(err.msg) }
assert values == ['value1', 'value2'] assert values == ['value1', 'value2']
flags := [ flags := [
@ -40,7 +40,7 @@ fn test_if_string_flag_parses() {
}, },
] ]
values = flags.get_strings('flag') or { panic(err) } values = flags.get_strings('flag') or { panic(err.msg) }
assert values == ['a', 'b', 'c'] assert values == ['a', 'b', 'c']
} }
@ -50,20 +50,20 @@ fn test_if_bool_flag_parses() {
name: 'flag' name: 'flag'
} }
mut value := false mut value := false
flag.parse(['-flag'], false) or { panic(err) } flag.parse(['-flag'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == true assert value == true
flag.parse(['-flag', 'false'], false) or { panic(err) } flag.parse(['-flag', 'false'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == false assert value == false
flag.parse(['-flag', 'true'], false) or { panic(err) } flag.parse(['-flag', 'true'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == true assert value == true
flag.parse(['-flag=false'], false) or { panic(err) } flag.parse(['-flag=false'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == false assert value == false
flag.parse(['-flag=true'], false) or { panic(err) } flag.parse(['-flag=true'], false) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == true assert value == true
} }
@ -74,8 +74,8 @@ fn test_if_int_flag_parses() {
} }
mut value := 0 mut value := 0
flag.parse(['-flag', '42'], false) or { panic(err) } flag.parse(['-flag', '42'], false) or { panic(err.msg) }
value = flag.get_int() or { panic(err) } value = flag.get_int() or { panic(err.msg) }
assert value == 42 assert value == 42
flag = cli.Flag{ flag = cli.Flag{
@ -83,8 +83,8 @@ fn test_if_int_flag_parses() {
name: 'flag' name: 'flag'
} }
flag.parse(['-flag=45'], false) or { panic(err) } flag.parse(['-flag=45'], false) or { panic(err.msg) }
value = flag.get_int() or { panic(err) } value = flag.get_int() or { panic(err.msg) }
assert value == 45 assert value == 45
flag = cli.Flag{ flag = cli.Flag{
@ -93,9 +93,9 @@ fn test_if_int_flag_parses() {
multiple: true multiple: true
} }
flag.parse(['-flag=42'], false) or { panic(err) } flag.parse(['-flag=42'], false) or { panic(err.msg) }
flag.parse(['-flag=45'], false) or { panic(err) } flag.parse(['-flag=45'], false) or { panic(err.msg) }
mut values := flag.get_ints() or { panic(err) } mut values := flag.get_ints() or { panic(err.msg) }
assert values == [42, 45] assert values == [42, 45]
flags := [ flags := [
@ -111,7 +111,7 @@ fn test_if_int_flag_parses() {
}, },
] ]
values = flags.get_ints('flag') or { panic(err) } values = flags.get_ints('flag') or { panic(err.msg) }
assert values == [1, 2, 3] assert values == [1, 2, 3]
} }
@ -121,8 +121,8 @@ fn test_if_float_flag_parses() {
name: 'flag' name: 'flag'
} }
mut value := f64(0) mut value := f64(0)
flag.parse(['-flag', '3.14158'], false) or { panic(err) } flag.parse(['-flag', '3.14158'], false) or { panic(err.msg) }
value = flag.get_float() or { panic(err) } value = flag.get_float() or { panic(err.msg) }
assert value == 3.14158 assert value == 3.14158
flag = cli.Flag{ flag = cli.Flag{
@ -130,9 +130,9 @@ fn test_if_float_flag_parses() {
name: 'flag' name: 'flag'
} }
flag.parse(['-flag=3.14159'], false) or { panic(err) } flag.parse(['-flag=3.14159'], false) or { panic(err.msg) }
assert flag.value[0].f64() == 3.14159 assert flag.value[0].f64() == 3.14159
value = flag.get_float() or { panic(err) } value = flag.get_float() or { panic(err.msg) }
assert value == 3.14159 assert value == 3.14159
flag = cli.Flag{ flag = cli.Flag{
@ -141,9 +141,9 @@ fn test_if_float_flag_parses() {
multiple: true multiple: true
} }
flag.parse(['-flag=3.1'], false) or { panic(err) } flag.parse(['-flag=3.1'], false) or { panic(err.msg) }
flag.parse(['-flag=1.3'], false) or { panic(err) } flag.parse(['-flag=1.3'], false) or { panic(err.msg) }
mut values := flag.get_floats() or { panic(err) } mut values := flag.get_floats() or { panic(err.msg) }
assert values == [3.1, 1.3] assert values == [3.1, 1.3]
flags := [ flags := [
@ -159,7 +159,7 @@ fn test_if_float_flag_parses() {
}, },
] ]
values = flags.get_floats('flag') or { panic(err) } values = flags.get_floats('flag') or { panic(err.msg) }
assert values == [1.1, 2.2, 3.3] assert values == [1.1, 2.2, 3.3]
} }
@ -170,8 +170,8 @@ fn test_if_flag_parses_with_abbrev() {
abbrev: 'f' abbrev: 'f'
} }
mut value := false mut value := false
flag.parse(['--flag'], true) or { panic(err) } flag.parse(['--flag'], true) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == true assert value == true
value = false value = false
@ -180,8 +180,8 @@ fn test_if_flag_parses_with_abbrev() {
name: 'flag' name: 'flag'
abbrev: 'f' abbrev: 'f'
} }
flag.parse(['-f'], true) or { panic(err) } flag.parse(['-f'], true) or { panic(err.msg) }
value = flag.get_bool() or { panic(err) } value = flag.get_bool() or { panic(err.msg) }
assert value == true assert value == true
} }
@ -191,7 +191,7 @@ fn test_if_multiple_value_on_single_value() {
name: 'flag' name: 'flag'
} }
flag.parse(['-flag', '3.14158'], false) or { panic(err) } flag.parse(['-flag', '3.14158'], false) or { panic(err.msg) }
if _ := flag.parse(['-flag', '3.222'], false) { if _ := flag.parse(['-flag', '3.222'], false) {
panic("No multiple value flag don't raise an error!") panic("No multiple value flag don't raise an error!")

View File

@ -110,7 +110,7 @@ pub fn (mut d Digest) checksum() []byte {
tmp[0] = 0x80 tmp[0] = 0x80
pad := ((55 - d.len) % 64) // calculate number of padding bytes pad := ((55 - d.len) % 64) // calculate number of padding bytes
binary.little_endian_put_u64(mut tmp[1 + pad..], d.len << 3) // append length in bits binary.little_endian_put_u64(mut tmp[1 + pad..], d.len << 3) // append length in bits
d.write(tmp[..1 + pad + 8]) or { panic(err) } d.write(tmp[..1 + pad + 8]) or { panic(err.msg) }
// The previous write ensures that a whole number of // The previous write ensures that a whole number of
// blocks (i.e. a multiple of 64 bytes) have been hashed. // blocks (i.e. a multiple of 64 bytes) have been hashed.
if d.nx != 0 { if d.nx != 0 {
@ -127,7 +127,7 @@ pub fn (mut d Digest) checksum() []byte {
// sum returns the MD5 checksum of the data. // sum returns the MD5 checksum of the data.
pub fn sum(data []byte) []byte { pub fn sum(data []byte) []byte {
mut d := new() mut d := new()
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
return d.checksum() return d.checksum()
} }

View File

@ -109,14 +109,14 @@ fn (mut d Digest) checksum() []byte {
mut tmp := []byte{len: (64)} mut tmp := []byte{len: (64)}
tmp[0] = 0x80 tmp[0] = 0x80
if int(len) % 64 < 56 { if int(len) % 64 < 56 {
d.write(tmp[..56 - int(len) % 64]) or { panic(err) } d.write(tmp[..56 - int(len) % 64]) or { panic(err.msg) }
} else { } else {
d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err) } d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err.msg) }
} }
// Length in bits. // Length in bits.
len <<= 3 len <<= 3
binary.big_endian_put_u64(mut tmp, len) binary.big_endian_put_u64(mut tmp, len)
d.write(tmp[..8]) or { panic(err) } d.write(tmp[..8]) or { panic(err.msg) }
mut digest := []byte{len: (size)} mut digest := []byte{len: (size)}
binary.big_endian_put_u32(mut digest, d.h[0]) binary.big_endian_put_u32(mut digest, d.h[0])
binary.big_endian_put_u32(mut digest[4..], d.h[1]) binary.big_endian_put_u32(mut digest[4..], d.h[1])
@ -129,7 +129,7 @@ fn (mut d Digest) checksum() []byte {
// sum returns the SHA-1 checksum of the bytes passed in `data`. // sum returns the SHA-1 checksum of the bytes passed in `data`.
pub fn sum(data []byte) []byte { pub fn sum(data []byte) []byte {
mut d := new() mut d := new()
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
return d.checksum() return d.checksum()
} }

View File

@ -147,14 +147,14 @@ fn (mut d Digest) checksum() []byte {
mut tmp := []byte{len: (64)} mut tmp := []byte{len: (64)}
tmp[0] = 0x80 tmp[0] = 0x80
if int(len) % 64 < 56 { if int(len) % 64 < 56 {
d.write(tmp[..56 - int(len) % 64]) or { panic(err) } d.write(tmp[..56 - int(len) % 64]) or { panic(err.msg) }
} else { } else {
d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err) } d.write(tmp[..64 + 56 - int(len) % 64]) or { panic(err.msg) }
} }
// Length in bits. // Length in bits.
len <<= u64(3) len <<= u64(3)
binary.big_endian_put_u64(mut tmp, len) binary.big_endian_put_u64(mut tmp, len)
d.write(tmp[..8]) or { panic(err) } d.write(tmp[..8]) or { panic(err.msg) }
if d.nx != 0 { if d.nx != 0 {
panic('d.nx != 0') panic('d.nx != 0')
} }
@ -181,14 +181,14 @@ pub fn sum(data []byte) []byte {
// sum256 returns the SHA256 checksum of the data. // sum256 returns the SHA256 checksum of the data.
pub fn sum256(data []byte) []byte { pub fn sum256(data []byte) []byte {
mut d := new() mut d := new()
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
return d.checksum() return d.checksum()
} }
// sum224 returns the SHA224 checksum of the data. // sum224 returns the SHA224 checksum of the data.
pub fn sum224(data []byte) []byte { pub fn sum224(data []byte) []byte {
mut d := new224() mut d := new224()
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
sum := d.checksum() sum := d.checksum()
sum224 := []byte{len: (size224)} sum224 := []byte{len: (size224)}
copy(sum224, sum[..size224]) copy(sum224, sum[..size224])

View File

@ -219,15 +219,15 @@ fn (mut d Digest) checksum() []byte {
mut tmp := []byte{len: (128)} mut tmp := []byte{len: (128)}
tmp[0] = 0x80 tmp[0] = 0x80
if int(len) % 128 < 112 { if int(len) % 128 < 112 {
d.write(tmp[..112 - int(len) % 128]) or { panic(err) } d.write(tmp[..112 - int(len) % 128]) or { panic(err.msg) }
} else { } else {
d.write(tmp[..128 + 112 - int(len) % 128]) or { panic(err) } d.write(tmp[..128 + 112 - int(len) % 128]) or { panic(err.msg) }
} }
// Length in bits. // Length in bits.
len <<= u64(3) len <<= u64(3)
binary.big_endian_put_u64(mut tmp, u64(0)) // upper 64 bits are always zero, because len variable has type u64 binary.big_endian_put_u64(mut tmp, u64(0)) // upper 64 bits are always zero, because len variable has type u64
binary.big_endian_put_u64(mut tmp[8..], len) binary.big_endian_put_u64(mut tmp[8..], len)
d.write(tmp[..16]) or { panic(err) } d.write(tmp[..16]) or { panic(err.msg) }
if d.nx != 0 { if d.nx != 0 {
panic('d.nx != 0') panic('d.nx != 0')
} }
@ -248,14 +248,14 @@ fn (mut d Digest) checksum() []byte {
// sum512 returns the SHA512 checksum of the data. // sum512 returns the SHA512 checksum of the data.
pub fn sum512(data []byte) []byte { pub fn sum512(data []byte) []byte {
mut d := new_digest(.sha512) mut d := new_digest(.sha512)
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
return d.checksum() return d.checksum()
} }
// sum384 returns the SHA384 checksum of the data. // sum384 returns the SHA384 checksum of the data.
pub fn sum384(data []byte) []byte { pub fn sum384(data []byte) []byte {
mut d := new_digest(.sha384) mut d := new_digest(.sha384)
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
sum := d.checksum() sum := d.checksum()
sum384 := []byte{len: (size384)} sum384 := []byte{len: (size384)}
copy(sum384, sum[..size384]) copy(sum384, sum[..size384])
@ -265,7 +265,7 @@ pub fn sum384(data []byte) []byte {
// sum512_224 returns the Sum512/224 checksum of the data. // sum512_224 returns the Sum512/224 checksum of the data.
pub fn sum512_224(data []byte) []byte { pub fn sum512_224(data []byte) []byte {
mut d := new_digest(.sha512_224) mut d := new_digest(.sha512_224)
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
sum := d.checksum() sum := d.checksum()
sum224 := []byte{len: (size224)} sum224 := []byte{len: (size224)}
copy(sum224, sum[..size224]) copy(sum224, sum[..size224])
@ -275,7 +275,7 @@ pub fn sum512_224(data []byte) []byte {
// sum512_256 returns the Sum512/256 checksum of the data. // sum512_256 returns the Sum512/256 checksum of the data.
pub fn sum512_256(data []byte) []byte { pub fn sum512_256(data []byte) []byte {
mut d := new_digest(.sha512_256) mut d := new_digest(.sha512_256)
d.write(data) or { panic(err) } d.write(data) or { panic(err.msg) }
sum := d.checksum() sum := d.checksum()
sum256 := []byte{len: (size256)} sum256 := []byte{len: (size256)}
copy(sum256, sum[..size256]) copy(sum256, sum[..size256])

View File

@ -40,7 +40,7 @@ fn test_can_compile_main_program() {
fn v_compile(vopts string) os.Result { fn v_compile(vopts string) os.Result {
cmd := '"$vexe" -showcc $vopts' cmd := '"$vexe" -showcc $vopts'
eprintln('>>> v_compile cmd: $cmd') eprintln('>>> v_compile cmd: $cmd')
res := os.exec(cmd) or { panic(err) } res := os.exec(cmd) or { panic(err.msg) }
eprintln('>>> v_compile res: $res') eprintln('>>> v_compile res: $res')
// assert res.exit_code == 0 // assert res.exit_code == 0
$if !windows { $if !windows {

View File

@ -46,10 +46,10 @@ pub fn (mut r Reader) read() ?[]string {
// mut records := []string{} // mut records := []string{}
// for { // for {
// record := r.read_record() or { // record := r.read_record() or {
// if error(err).error == err_eof.error { // if err.error == err_eof.error {
// return records // return records
// } else { // } else {
// return error(err) // return err
// } // }
// } // }
// records << record // records << record

View File

@ -162,7 +162,7 @@ fn gg_init_sokol_window(user_data voidptr) {
font_path: g.config.font_path font_path: g.config.font_path
custom_bold_font_path: g.config.custom_bold_font_path custom_bold_font_path: g.config.custom_bold_font_path
scale: dpi_scale() scale: dpi_scale()
) or { panic(err) } ) or { panic(err.msg) }
// println('FT took ${time.ticks()-t} ms') // println('FT took ${time.ticks()-t} ms')
g.font_inited = true g.font_inited = true
} else { } else {
@ -174,7 +174,7 @@ fn gg_init_sokol_window(user_data voidptr) {
bytes_mono: g.config.font_bytes_mono bytes_mono: g.config.font_bytes_mono
bytes_italic: g.config.font_bytes_italic bytes_italic: g.config.font_bytes_italic
scale: sapp.dpi_scale() scale: sapp.dpi_scale()
) or { panic(err) } ) or { panic(err.msg) }
g.font_inited = true g.font_inited = true
} else { } else {
sfont := system_font_path() sfont := system_font_path()
@ -183,7 +183,7 @@ fn gg_init_sokol_window(user_data voidptr) {
font_path: sfont font_path: sfont
custom_bold_font_path: g.config.custom_bold_font_path custom_bold_font_path: g.config.custom_bold_font_path
scale: sapp.dpi_scale() scale: sapp.dpi_scale()
) or { panic(err) } ) or { panic(err.msg) }
g.font_inited = true g.font_inited = true
} }
} }

View File

@ -3,7 +3,7 @@ import io
fn read_file(file string, cap int) []string { fn read_file(file string, cap int) []string {
mut lines := []string{} mut lines := []string{}
mut f := os.open(file) or { panic(err) } mut f := os.open(file) or { panic(err.msg) }
defer { defer {
f.close() f.close()
} }

View File

@ -12,7 +12,7 @@ fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder') eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all(tfolder) or { } os.rmdir_all(tfolder) or { }
assert !os.is_dir(tfolder) assert !os.is_dir(tfolder)
os.mkdir_all(tfolder) or { panic(err) } os.mkdir_all(tfolder) or { panic(err.msg) }
os.chdir(tfolder) os.chdir(tfolder)
assert os.is_dir(tfolder) assert os.is_dir(tfolder)
} }

View File

@ -370,7 +370,7 @@ struct Info {
} }
fn test_decode_null_object() { fn test_decode_null_object() {
info := json.decode(Info, '{"id": 22, "items": null, "maps": null}') or { panic(err) } info := json.decode(Info, '{"id": 22, "items": null, "maps": null}') or { panic(err.msg) }
assert info.id == 22 assert info.id == 22
assert '$info.items' == '[]' assert '$info.items' == '[]'
assert '$info.maps' == '{}' assert '$info.maps' == '{}'

View File

@ -106,7 +106,7 @@ pub fn (mut l Log) close() {
fn (mut l Log) log_file(s string, level Level) { fn (mut l Log) log_file(s string, level Level) {
timestamp := time.now().format_ss() timestamp := time.now().format_ss()
e := tag_to_file(level) e := tag_to_file(level)
l.ofile.writeln('$timestamp [$e] $s') or { panic(err) } l.ofile.writeln('$timestamp [$e] $s') or { panic(err.msg) }
} }
// log_cli writes log line `s` with `level` to stdout. // log_cli writes log line `s` with `level` to stdout.

View File

@ -56,7 +56,7 @@ fn (mut dtp DTP) read() ?[]byte {
} }
fn (mut dtp DTP) close() { fn (mut dtp DTP) close() {
dtp.conn.close() or { panic(err) } dtp.conn.close() or { panic(err.msg) }
} }
struct FTP { struct FTP {

View File

@ -8,14 +8,14 @@ fn test_ftp_cleint() {
// that is why it is not a very good idea to run it in CI. // that is why it is not a very good idea to run it in CI.
// If you want to run it manually, use: // If you want to run it manually, use:
// `v -d network vlib/net/ftp/ftp_test.v` // `v -d network vlib/net/ftp/ftp_test.v`
ftp_client_test_inside() or { panic(err) } ftp_client_test_inside() or { panic(err.msg) }
} }
fn ftp_client_test_inside() ? { fn ftp_client_test_inside() ? {
mut zftp := ftp.new() mut zftp := ftp.new()
// eprintln(zftp) // eprintln(zftp)
defer { defer {
zftp.close() or { panic(err) } zftp.close() or { panic(err.msg) }
} }
connect_result := zftp.connect('ftp.redhat.com') ? connect_result := zftp.connect('ftp.redhat.com') ?
assert connect_result assert connect_result

View File

@ -25,7 +25,7 @@ mut:
fn (mut dom DocumentObjectModel) print_debug(data string) { fn (mut dom DocumentObjectModel) print_debug(data string) {
$if debug { $if debug {
if data.len > 0 { if data.len > 0 {
dom.debug_file.writeln(data) or { panic(err) } dom.debug_file.writeln(data) or { panic(err.msg) }
} }
} }
} }

View File

@ -53,7 +53,7 @@ fn (parser Parser) builder_str() string {
fn (mut parser Parser) print_debug(data string) { fn (mut parser Parser) print_debug(data string) {
$if debug { $if debug {
if data.len > 0 { if data.len > 0 {
parser.debug_file.writeln(data) or { panic(err) } parser.debug_file.writeln(data) or { panic(err.msg) }
} }
} }
} }

View File

@ -9,7 +9,7 @@ pub fn download_file(url string, out string) ? {
$if debug_http ? { $if debug_http ? {
println('download file url=$url out=$out') println('download file url=$url out=$out')
} }
s := get(url) or { return error(err) } s := get(url) or { return err }
os.write_file(out, s.text) ? os.write_file(out, s.text) ?
// download_file_with_progress(url, out, empty, empty) // download_file_with_progress(url, out, empty, empty)
} }

View File

@ -34,7 +34,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response {
fn test_http_fetch_bare() { fn test_http_fetch_bare() {
$if !network ? { return } $if !network ? { return }
responses := http_fetch_mock([], FetchConfig{}) or { responses := http_fetch_mock([], FetchConfig{}) or {
panic(err) panic(err.msg)
} }
for response in responses { for response in responses {
assert response.status_code == 200 assert response.status_code == 200
@ -46,11 +46,11 @@ fn test_http_fetch_with_data() {
responses := http_fetch_mock(['POST', 'PUT', 'PATCH', 'DELETE'], { responses := http_fetch_mock(['POST', 'PUT', 'PATCH', 'DELETE'], {
data: 'hello world' data: 'hello world'
}) or { }) or {
panic(err) panic(err.msg)
} }
for response in responses { for response in responses {
payload := json.decode(HttpbinResponseBody,response.text) or { payload := json.decode(HttpbinResponseBody,response.text) or {
panic(err) panic(err.msg)
} }
assert payload.data == 'hello world' assert payload.data == 'hello world'
} }
@ -64,11 +64,11 @@ fn test_http_fetch_with_params() {
'c': 'd' 'c': 'd'
} }
}) or { }) or {
panic(err) panic(err.msg)
} }
for response in responses { for response in responses {
// payload := json.decode(HttpbinResponseBody,response.text) or { // payload := json.decode(HttpbinResponseBody,response.text) or {
// panic(err) // panic(err.msg)
// } // }
assert response.status_code == 200 assert response.status_code == 200
// TODO // TODO
@ -84,11 +84,11 @@ fn test_http_fetch_with_headers() {
'Test-Header': 'hello world' 'Test-Header': 'hello world'
} }
}) or { }) or {
panic(err) panic(err.msg)
} }
for response in responses { for response in responses {
// payload := json.decode(HttpbinResponseBody,response.text) or { // payload := json.decode(HttpbinResponseBody,response.text) or {
// panic(err) // panic(err.msg)
// } // }
assert response.status_code == 200 assert response.status_code == 200
// TODO // TODO

View File

@ -16,7 +16,7 @@ fn test_http_get_from_vlang_utc_now() {
for url in urls { for url in urls {
println('Test getting current time from $url by http.get') println('Test getting current time from $url by http.get')
res := http.get(url) or { res := http.get(url) or {
panic(err) panic(err.msg)
} }
assert 200 == res.status_code assert 200 == res.status_code
assert res.text.len > 0 assert res.text.len > 0
@ -40,7 +40,7 @@ fn test_public_servers() {
for url in urls { for url in urls {
println('Testing http.get on public url: $url ') println('Testing http.get on public url: $url ')
res := http.get(url) or { res := http.get(url) or {
panic(err) panic(err.msg)
} }
assert 200 == res.status_code assert 200 == res.status_code
assert res.text.len > 0 assert res.text.len > 0
@ -54,7 +54,7 @@ fn test_relative_redirects() {
return return
} // tempfix periodic: httpbin relative redirects are broken } // tempfix periodic: httpbin relative redirects are broken
res := http.get('https://httpbin.org/relative-redirect/3?abc=xyz') or { res := http.get('https://httpbin.org/relative-redirect/3?abc=xyz') or {
panic(err) panic(err.msg)
} }
assert 200 == res.status_code assert 200 == res.status_code
assert res.text.len > 0 assert res.text.len > 0

View File

@ -7,9 +7,9 @@ const (
) )
fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) { fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) {
mut server := net.listen_tcp(server_port) or { panic(err) } mut server := net.listen_tcp(server_port) or { panic(err.msg) }
mut client := net.dial_tcp('127.0.0.1:$server_port') or { panic(err) } mut client := net.dial_tcp('127.0.0.1:$server_port') or { panic(err.msg) }
mut socket := server.accept() or { panic(err) } mut socket := server.accept() or { panic(err.msg) }
$if debug_peer_ip ? { $if debug_peer_ip ? {
ip := con.peer_ip() or { '$err' } ip := con.peer_ip() or { '$err' }
eprintln('connection peer_ip: $ip') eprintln('connection peer_ip: $ip')

View File

@ -44,8 +44,8 @@ fn echo() ? {
} }
fn test_tcp() { fn test_tcp() {
mut l := net.listen_tcp(test_port) or { panic(err) } mut l := net.listen_tcp(test_port) or { panic(err.msg) }
go echo_server(mut l) go echo_server(mut l)
echo() or { panic(err) } echo() or { panic(err.msg) }
l.close() or { } l.close() or { }
} }

View File

@ -51,8 +51,8 @@ fn echo() ? {
} }
fn test_tcp() { fn test_tcp() {
mut l := unix.listen_stream(test_port) or { panic(err) } mut l := unix.listen_stream(test_port) or { panic(err.msg) }
go echo_server(mut l) go echo_server(mut l)
echo() or { panic(err) } echo() or { panic(err.msg) }
l.close() or { } l.close() or { }
} }

View File

@ -22,7 +22,7 @@ struct Foo {
} }
fn test_orm_sqlite() { fn test_orm_sqlite() {
db := sqlite.connect(':memory:') or { panic(err) } db := sqlite.connect(':memory:') or { panic(err.msg) }
db.exec('drop table if exists User') db.exec('drop table if exists User')
db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);") db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")
name := 'Peter' name := 'Peter'
@ -230,7 +230,7 @@ fn test_orm_pg() {
eprintln(term.red('NB: this test requires VDB_NAME and VDB_USER env variables to be set')) eprintln(term.red('NB: this test requires VDB_NAME and VDB_USER env variables to be set'))
return return
} }
db := pg.connect(dbname: dbname, user: dbuser) or { panic(err) } db := pg.connect(dbname: dbname, user: dbuser) or { panic(err.msg) }
_ = db _ = db
nr_modules := db.select count from modules nr_modules := db.select count from modules
//nr_modules := db.select count from Modules where id == 1 //nr_modules := db.select count from Modules where id == 1

View File

@ -11,14 +11,14 @@ fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder') eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all(tfolder) or { } os.rmdir_all(tfolder) or { }
assert !os.is_dir(tfolder) assert !os.is_dir(tfolder)
os.mkdir_all(tfolder) or { panic(err) } os.mkdir_all(tfolder) or { panic(err.msg) }
os.chdir(tfolder) os.chdir(tfolder)
assert os.is_dir(tfolder) assert os.is_dir(tfolder)
} }
fn testsuite_end() { fn testsuite_end() {
os.chdir(os.wd_at_startup) os.chdir(os.wd_at_startup)
os.rmdir_all(tfolder) or { panic(err) } os.rmdir_all(tfolder) or { panic(err.msg) }
assert !os.is_dir(tfolder) assert !os.is_dir(tfolder)
} }
@ -27,7 +27,7 @@ fn test_inode_file_type() {
mut file := os.open_file(filename, 'w', 0o600) or { return } mut file := os.open_file(filename, 'w', 0o600) or { return }
file.close() file.close()
mode := os.inode(filename) mode := os.inode(filename)
os.rm(filename) or { panic(err) } os.rm(filename) or { panic(err.msg) }
assert mode.typ == .regular assert mode.typ == .regular
} }

View File

@ -61,8 +61,8 @@ pub fn cp_all(src string, dst string, overwrite bool) ? {
} }
} }
cp_all(sp, dp, overwrite) or { cp_all(sp, dp, overwrite) or {
rmdir(dp) or { return error(err) } rmdir(dp) or { return err }
return error(err) return err
} }
} }
} }
@ -507,7 +507,7 @@ pub fn cache_dir() string {
} }
cdir := join_path(home_dir(), '.cache') cdir := join_path(home_dir(), '.cache')
if !is_dir(cdir) && !is_link(cdir) { if !is_dir(cdir) && !is_link(cdir) {
mkdir(cdir) or { panic(err) } mkdir(cdir) or { panic(err.msg) }
} }
return cdir return cdir
} }

View File

@ -15,7 +15,7 @@ fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder') eprintln('testsuite_begin, tfolder = $tfolder')
os.rmdir_all(tfolder) or { } os.rmdir_all(tfolder) or { }
assert !os.is_dir(tfolder) assert !os.is_dir(tfolder)
os.mkdir_all(tfolder) or { panic(err) } os.mkdir_all(tfolder) or { panic(err.msg) }
os.chdir(tfolder) os.chdir(tfolder)
assert os.is_dir(tfolder) assert os.is_dir(tfolder)
// println('args_at_start: $args_at_start') // println('args_at_start: $args_at_start')
@ -37,13 +37,13 @@ fn test_open_file() {
assert err.msg == 'No such file or directory' assert err.msg == 'No such file or directory'
os.File{} os.File{}
} }
mut file := os.open_file(filename, 'w+', 0o666) or { panic(err) } mut file := os.open_file(filename, 'w+', 0o666) or { panic(err.msg) }
file.write_str(hello) or { panic(err) } file.write_str(hello) or { panic(err.msg) }
file.close() file.close()
assert hello.len == os.file_size(filename) assert hello.len == os.file_size(filename)
read_hello := os.read_file(filename) or { panic('error reading file $filename') } read_hello := os.read_file(filename) or { panic('error reading file $filename') }
assert hello == read_hello assert hello == read_hello
os.rm(filename) or { panic(err) } os.rm(filename) or { panic(err.msg) }
} }
fn test_open_file_binary() { fn test_open_file_binary() {
@ -53,14 +53,14 @@ fn test_open_file_binary() {
assert err.msg == 'No such file or directory' assert err.msg == 'No such file or directory'
os.File{} os.File{}
} }
mut file := os.open_file(filename, 'wb+', 0o666) or { panic(err) } mut file := os.open_file(filename, 'wb+', 0o666) or { panic(err.msg) }
bytes := hello.bytes() bytes := hello.bytes()
file.write_bytes(bytes.data, bytes.len) file.write_bytes(bytes.data, bytes.len)
file.close() file.close()
assert hello.len == os.file_size(filename) assert hello.len == os.file_size(filename)
read_hello := os.read_bytes(filename) or { panic('error reading file $filename') } read_hello := os.read_bytes(filename) or { panic('error reading file $filename') }
assert bytes == read_hello assert bytes == read_hello
os.rm(filename) or { panic(err) } os.rm(filename) or { panic(err.msg) }
} }
// fn test_file_get_line() { // fn test_file_get_line() {
@ -86,24 +86,24 @@ fn test_open_file_binary() {
fn test_create_file() { fn test_create_file() {
filename := './test1.txt' filename := './test1.txt'
hello := 'hello world!' hello := 'hello world!'
mut f := os.create(filename) or { panic(err) } mut f := os.create(filename) or { panic(err.msg) }
f.write_str(hello) or { panic(err) } f.write_str(hello) or { panic(err.msg) }
f.close() f.close()
assert hello.len == os.file_size(filename) assert hello.len == os.file_size(filename)
os.rm(filename) or { panic(err) } os.rm(filename) or { panic(err.msg) }
} }
fn test_is_file() { fn test_is_file() {
// Setup // Setup
work_dir := os.join_path(os.getwd(), 'is_file_test') work_dir := os.join_path(os.getwd(), 'is_file_test')
os.mkdir_all(work_dir) or { panic(err) } os.mkdir_all(work_dir) or { panic(err.msg) }
tfile := os.join_path(work_dir, 'tmp_file') tfile := os.join_path(work_dir, 'tmp_file')
// Test things that shouldn't be a file // Test things that shouldn't be a file
assert os.is_file(work_dir) == false assert os.is_file(work_dir) == false
assert os.is_file('non-existent_file.tmp') == false assert os.is_file('non-existent_file.tmp') == false
// Test file // Test file
tfile_content := 'temporary file' tfile_content := 'temporary file'
os.write_file(tfile, tfile_content) or { panic(err) } os.write_file(tfile, tfile_content) or { panic(err.msg) }
assert os.is_file(tfile) assert os.is_file(tfile)
// Test dir symlinks // Test dir symlinks
$if windows { $if windows {
@ -126,11 +126,11 @@ fn test_is_file() {
fn test_write_and_read_string_to_file() { fn test_write_and_read_string_to_file() {
filename := './test1.txt' filename := './test1.txt'
hello := 'hello world!' hello := 'hello world!'
os.write_file(filename, hello) or { panic(err) } os.write_file(filename, hello) or { panic(err.msg) }
assert hello.len == os.file_size(filename) assert hello.len == os.file_size(filename)
read_hello := os.read_file(filename) or { panic('error reading file $filename') } read_hello := os.read_file(filename) or { panic('error reading file $filename') }
assert hello == read_hello assert hello == read_hello
os.rm(filename) or { panic(err) } os.rm(filename) or { panic(err.msg) }
} }
// test_write_and_read_bytes checks for regressions made in the functions // test_write_and_read_bytes checks for regressions made in the functions
@ -166,16 +166,16 @@ fn test_write_and_read_bytes() {
assert nread == 0 assert nread == 0
file_read.close() file_read.close()
// We finally delete the test file. // We finally delete the test file.
os.rm(file_name) or { panic(err) } os.rm(file_name) or { panic(err.msg) }
} }
fn test_create_and_delete_folder() { fn test_create_and_delete_folder() {
folder := './test1' folder := './test1'
os.mkdir(folder) or { panic(err) } os.mkdir(folder) or { panic(err.msg) }
assert os.is_dir(folder) assert os.is_dir(folder)
folder_contents := os.ls(folder) or { panic(err) } folder_contents := os.ls(folder) or { panic(err.msg) }
assert folder_contents.len == 0 assert folder_contents.len == 0
os.rmdir(folder) or { panic(err) } os.rmdir(folder) or { panic(err.msg) }
folder_exists := os.is_dir(folder) folder_exists := os.is_dir(folder)
assert folder_exists == false assert folder_exists == false
} }
@ -189,63 +189,63 @@ fn walk_callback(file string) {
fn test_walk() { fn test_walk() {
folder := 'test_walk' folder := 'test_walk'
os.mkdir(folder) or { panic(err) } os.mkdir(folder) or { panic(err.msg) }
file1 := folder + os.path_separator + 'test1' file1 := folder + os.path_separator + 'test1'
os.write_file(file1, 'test-1') or { panic(err) } os.write_file(file1, 'test-1') or { panic(err.msg) }
os.walk(folder, walk_callback) os.walk(folder, walk_callback)
os.rm(file1) or { panic(err) } os.rm(file1) or { panic(err.msg) }
os.rmdir(folder) or { panic(err) } os.rmdir(folder) or { panic(err.msg) }
} }
fn test_cp() { fn test_cp() {
old_file_name := 'cp_example.txt' old_file_name := 'cp_example.txt'
new_file_name := 'cp_new_example.txt' new_file_name := 'cp_new_example.txt'
os.write_file(old_file_name, 'Test data 1 2 3, V is awesome #$%^[]!~') or { panic(err) } os.write_file(old_file_name, 'Test data 1 2 3, V is awesome #$%^[]!~') or { panic(err.msg) }
os.cp(old_file_name, new_file_name) or { panic('$err') } os.cp(old_file_name, new_file_name) or { panic('$err') }
old_file := os.read_file(old_file_name) or { panic(err) } old_file := os.read_file(old_file_name) or { panic(err.msg) }
new_file := os.read_file(new_file_name) or { panic(err) } new_file := os.read_file(new_file_name) or { panic(err.msg) }
assert old_file == new_file assert old_file == new_file
os.rm(old_file_name) or { panic(err) } os.rm(old_file_name) or { panic(err.msg) }
os.rm(new_file_name) or { panic(err) } os.rm(new_file_name) or { panic(err.msg) }
} }
fn test_mv() { fn test_mv() {
work_dir := os.join_path(os.getwd(), 'mv_test') work_dir := os.join_path(os.getwd(), 'mv_test')
os.mkdir_all(work_dir) or { panic(err) } os.mkdir_all(work_dir) or { panic(err.msg) }
// Setup test files // Setup test files
tfile1 := os.join_path(work_dir, 'file') tfile1 := os.join_path(work_dir, 'file')
tfile2 := os.join_path(work_dir, 'file.test') tfile2 := os.join_path(work_dir, 'file.test')
tfile3 := os.join_path(work_dir, 'file.3') tfile3 := os.join_path(work_dir, 'file.3')
tfile_content := 'temporary file' tfile_content := 'temporary file'
os.write_file(tfile1, tfile_content) or { panic(err) } os.write_file(tfile1, tfile_content) or { panic(err.msg) }
os.write_file(tfile2, tfile_content) or { panic(err) } os.write_file(tfile2, tfile_content) or { panic(err.msg) }
// Setup test dirs // Setup test dirs
tdir1 := os.join_path(work_dir, 'dir') tdir1 := os.join_path(work_dir, 'dir')
tdir2 := os.join_path(work_dir, 'dir2') tdir2 := os.join_path(work_dir, 'dir2')
tdir3 := os.join_path(work_dir, 'dir3') tdir3 := os.join_path(work_dir, 'dir3')
os.mkdir(tdir1) or { panic(err) } os.mkdir(tdir1) or { panic(err.msg) }
os.mkdir(tdir2) or { panic(err) } os.mkdir(tdir2) or { panic(err.msg) }
// Move file with no extension to dir // Move file with no extension to dir
os.mv(tfile1, tdir1) or { panic(err) } os.mv(tfile1, tdir1) or { panic(err.msg) }
mut expected := os.join_path(tdir1, 'file') mut expected := os.join_path(tdir1, 'file')
assert os.exists(expected) && !is_dir(expected) == true assert os.exists(expected) && !is_dir(expected) == true
// Move dir with contents to other dir // Move dir with contents to other dir
os.mv(tdir1, tdir2) or { panic(err) } os.mv(tdir1, tdir2) or { panic(err.msg) }
expected = os.join_path(tdir2, 'dir') expected = os.join_path(tdir2, 'dir')
assert os.exists(expected) && is_dir(expected) == true assert os.exists(expected) && is_dir(expected) == true
expected = os.join_path(tdir2, 'dir', 'file') expected = os.join_path(tdir2, 'dir', 'file')
assert os.exists(expected) && !is_dir(expected) == true assert os.exists(expected) && !is_dir(expected) == true
// Move dir with contents to other dir (by renaming) // Move dir with contents to other dir (by renaming)
os.mv(os.join_path(tdir2, 'dir'), tdir3) or { panic(err) } os.mv(os.join_path(tdir2, 'dir'), tdir3) or { panic(err.msg) }
expected = tdir3 expected = tdir3
assert os.exists(expected) && is_dir(expected) == true assert os.exists(expected) && is_dir(expected) == true
assert os.is_dir_empty(tdir2) == true assert os.is_dir_empty(tdir2) == true
// Move file with extension to dir // Move file with extension to dir
os.mv(tfile2, tdir2) or { panic(err) } os.mv(tfile2, tdir2) or { panic(err.msg) }
expected = os.join_path(tdir2, 'file.test') expected = os.join_path(tdir2, 'file.test')
assert os.exists(expected) && !is_dir(expected) == true assert os.exists(expected) && !is_dir(expected) == true
// Move file to dir (by renaming) // Move file to dir (by renaming)
os.mv(os.join_path(tdir2, 'file.test'), tfile3) or { panic(err) } os.mv(os.join_path(tdir2, 'file.test'), tfile3) or { panic(err.msg) }
expected = tfile3 expected = tfile3
assert os.exists(expected) && !is_dir(expected) == true assert os.exists(expected) && !is_dir(expected) == true
} }
@ -253,22 +253,22 @@ fn test_mv() {
fn test_cp_all() { fn test_cp_all() {
// fileX -> dir/fileX // fileX -> dir/fileX
// NB: clean up of the files happens inside the cleanup_leftovers function // NB: clean up of the files happens inside the cleanup_leftovers function
os.write_file('ex1.txt', 'wow!') or { panic(err) } os.write_file('ex1.txt', 'wow!') or { panic(err.msg) }
os.mkdir('ex') or { panic(err) } os.mkdir('ex') or { panic(err.msg) }
os.cp_all('ex1.txt', 'ex', false) or { panic(err) } os.cp_all('ex1.txt', 'ex', false) or { panic(err.msg) }
old := os.read_file('ex1.txt') or { panic(err) } old := os.read_file('ex1.txt') or { panic(err.msg) }
new := os.read_file('ex/ex1.txt') or { panic(err) } new := os.read_file('ex/ex1.txt') or { panic(err.msg) }
assert old == new assert old == new
os.mkdir('ex/ex2') or { panic(err) } os.mkdir('ex/ex2') or { panic(err.msg) }
os.write_file('ex2.txt', 'great!') or { panic(err) } os.write_file('ex2.txt', 'great!') or { panic(err.msg) }
os.cp_all('ex2.txt', 'ex/ex2', false) or { panic(err) } os.cp_all('ex2.txt', 'ex/ex2', false) or { panic(err.msg) }
old2 := os.read_file('ex2.txt') or { panic(err) } old2 := os.read_file('ex2.txt') or { panic(err.msg) }
new2 := os.read_file('ex/ex2/ex2.txt') or { panic(err) } new2 := os.read_file('ex/ex2/ex2.txt') or { panic(err.msg) }
assert old2 == new2 assert old2 == new2
// recurring on dir -> local dir // recurring on dir -> local dir
os.cp_all('ex', './', true) or { panic(err) } os.cp_all('ex', './', true) or { panic(err.msg) }
// regression test for executive runs with overwrite := true // regression test for executive runs with overwrite := true
os.cp_all('ex', './', true) or { panic(err) } os.cp_all('ex', './', true) or { panic(err.msg) }
} }
fn test_realpath() { fn test_realpath() {
@ -282,10 +282,10 @@ fn test_tmpdir() {
tfile := t + os.path_separator + 'tmpfile.txt' tfile := t + os.path_separator + 'tmpfile.txt'
os.rm(tfile) or { } // just in case os.rm(tfile) or { } // just in case
tfile_content := 'this is a temporary file' tfile_content := 'this is a temporary file'
os.write_file(tfile, tfile_content) or { panic(err) } os.write_file(tfile, tfile_content) or { panic(err.msg) }
tfile_content_read := os.read_file(tfile) or { panic(err) } tfile_content_read := os.read_file(tfile) or { panic(err.msg) }
assert tfile_content_read == tfile_content assert tfile_content_read == tfile_content
os.rm(tfile) or { panic(err) } os.rm(tfile) or { panic(err.msg) }
} }
fn test_is_writable_folder() { fn test_is_writable_folder() {
@ -307,13 +307,13 @@ fn test_make_symlink_check_is_link_and_remove_symlink() {
symlink := 'tsymlink' symlink := 'tsymlink'
os.rm(symlink) or { } os.rm(symlink) or { }
os.rm(folder) or { } os.rm(folder) or { }
os.mkdir(folder) or { panic(err) } os.mkdir(folder) or { panic(err.msg) }
folder_contents := os.ls(folder) or { panic(err) } folder_contents := os.ls(folder) or { panic(err.msg) }
assert folder_contents.len == 0 assert folder_contents.len == 0
os.system('ln -s $folder $symlink') os.system('ln -s $folder $symlink')
assert os.is_link(symlink) == true assert os.is_link(symlink) == true
os.rm(symlink) or { panic(err) } os.rm(symlink) or { panic(err.msg) }
os.rm(folder) or { panic(err) } os.rm(folder) or { panic(err.msg) }
folder_exists := os.is_dir(folder) folder_exists := os.is_dir(folder)
assert folder_exists == false assert folder_exists == false
symlink_exists := os.is_link(symlink) symlink_exists := os.is_link(symlink)
@ -345,12 +345,12 @@ fn test_symlink() {
$if windows { $if windows {
return return
} }
os.mkdir('symlink') or { panic(err) } os.mkdir('symlink') or { panic(err.msg) }
os.symlink('symlink', 'symlink2') or { panic(err) } os.symlink('symlink', 'symlink2') or { panic(err.msg) }
assert os.exists('symlink2') assert os.exists('symlink2')
// cleanup // cleanup
os.rm('symlink') or { panic(err) } os.rm('symlink') or { panic(err.msg) }
os.rm('symlink2') or { panic(err) } os.rm('symlink2') or { panic(err.msg) }
} }
fn test_is_executable_writable_readable() { fn test_is_executable_writable_readable() {
@ -373,7 +373,7 @@ fn test_is_executable_writable_readable() {
assert os.is_executable(file_name) assert os.is_executable(file_name)
} }
// We finally delete the test file. // We finally delete the test file.
os.rm(file_name) or { panic(err) } os.rm(file_name) or { panic(err.msg) }
} }
fn test_ext() { fn test_ext() {
@ -457,8 +457,8 @@ fn test_write_file_array_bytes() {
for i in 0 .. maxn { for i in 0 .. maxn {
arr[i] = 65 + byte(i) arr[i] = 65 + byte(i)
} }
os.write_file_array(fpath, arr) or { panic(err) } os.write_file_array(fpath, arr) or { panic(err.msg) }
rarr := os.read_bytes(fpath) or { panic(err) } rarr := os.read_bytes(fpath) or { panic(err.msg) }
assert arr == rarr assert arr == rarr
// eprintln(arr.str()) // eprintln(arr.str())
// eprintln(rarr.str()) // eprintln(rarr.str())
@ -470,7 +470,7 @@ fn test_write_file_array_structs() {
for i in 0 .. maxn { for i in 0 .. maxn {
arr[i] = IntPoint{65 + i, 65 + i + 10} arr[i] = IntPoint{65 + i, 65 + i + 10}
} }
os.write_file_array(fpath, arr) or { panic(err) } os.write_file_array(fpath, arr) or { panic(err.msg) }
rarr := os.read_file_array<IntPoint>(fpath) rarr := os.read_file_array<IntPoint>(fpath)
assert rarr == arr assert rarr == arr
assert rarr.len == maxn assert rarr.len == maxn

View File

@ -7,7 +7,7 @@ fn no_lines(s string) string {
fn test_struct_readline() { fn test_struct_readline() {
// mut rl := Readline{} // mut rl := Readline{}
// eprintln('rl: $rl') // eprintln('rl: $rl')
// line := rl.read_line('Please, enter your name: ') or { panic(err) } // line := rl.read_line('Please, enter your name: ') or { panic(err.msg) }
// eprintln('line: $line') // eprintln('line: $line')
mut methods := []string{} mut methods := []string{}
$for method in Readline.methods { $for method in Readline.methods {

View File

@ -61,10 +61,10 @@ fn parse_range(input string) ?Range {
mut comparator_sets := []ComparatorSet{} mut comparator_sets := []ComparatorSet{}
for raw_comp_set in raw_comparator_sets { for raw_comp_set in raw_comparator_sets {
if can_expand(raw_comp_set) { if can_expand(raw_comp_set) {
s := expand_comparator_set(raw_comp_set) or { return error(err) } s := expand_comparator_set(raw_comp_set) or { return err }
comparator_sets << s comparator_sets << s
} else { } else {
s := parse_comparator_set(raw_comp_set) or { return error(err) } s := parse_comparator_set(raw_comp_set) or { return err }
comparator_sets << s comparator_sets << s
} }
} }

View File

@ -5,7 +5,7 @@ fn test_sqlite() {
return return
} }
mut db := sqlite.connect(':memory:') or { mut db := sqlite.connect(':memory:') or {
panic(err) panic(err.msg)
} }
assert db.is_open assert db.is_open
db.exec('drop table if exists users') db.exec('drop table if exists users')
@ -23,11 +23,11 @@ fn test_sqlite() {
code = db.exec_none('vacuum') code = db.exec_none('vacuum')
assert code == 101 assert code == 101
user := db.exec_one('select * from users where id = 3') or { user := db.exec_one('select * from users where id = 3') or {
panic(err) panic(err.msg)
} }
assert user.vals.len == 2 assert user.vals.len == 2
db.close() or { db.close() or {
panic(err) panic(err.msg)
} }
assert !db.is_open assert !db.is_open
} }

View File

@ -125,7 +125,7 @@ fn (mut ctx Context) termios_setup() ? {
os.signal(C.SIGCONT, fn () { os.signal(C.SIGCONT, fn () {
mut c := ctx_ptr mut c := ctx_ptr
if c != 0 { if c != 0 {
c.termios_setup() or { panic(err) } c.termios_setup() or { panic(err.msg) }
c.window_height, c.window_width = get_terminal_size() c.window_height, c.window_width = get_terminal_size()
mut event := &Event{ mut event := &Event{
typ: .resized typ: .resized

View File

@ -43,7 +43,7 @@ pub fn new_builder(pref &pref.Preferences) Builder {
} }
msvc := find_msvc(pref.m64) or { msvc := find_msvc(pref.m64) or {
if pref.ccompiler == 'msvc' { if pref.ccompiler == 'msvc' {
verror('Cannot find MSVC on this OS') // verror('Cannot find MSVC on this OS')
} }
MsvcResult{ MsvcResult{
valid: false valid: false
@ -205,7 +205,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string {
} else if !os.is_dir(dir) { } else if !os.is_dir(dir) {
verror("$dir isn't a directory!") verror("$dir isn't a directory!")
} }
mut files := os.ls(dir) or { panic(err) } mut files := os.ls(dir) or { panic(err.msg) }
if b.pref.is_verbose { if b.pref.is_verbose {
println('v_files_from_dir ("$dir")') println('v_files_from_dir ("$dir")')
} }

View File

@ -42,8 +42,8 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) {
b.pref.out_name_c = os.real_path(out_file) b.pref.out_name_c = os.real_path(out_file)
b.info('build_c($out_file)') b.info('build_c($out_file)')
output2 := b.gen_c(v_files) output2 := b.gen_c(v_files)
mut f := os.create(out_file) or { panic(err) } mut f := os.create(out_file) or { panic(err.msg) }
f.writeln(output2) or { panic(err) } f.writeln(output2) or { panic(err.msg) }
f.close() f.close()
if b.pref.is_stats { if b.pref.is_stats {
println('generated C source code size: ${util.bold((output2.count('\n') + 1).str())} lines, ${util.bold(output2.len.str())} bytes') println('generated C source code size: ${util.bold((output2.count('\n') + 1).str())} lines, ${util.bold(output2.len.str())} bytes')
@ -86,9 +86,9 @@ pub fn (mut b Builder) compile_c() {
bundle_name := b.pref.out_name.split('/').last() bundle_name := b.pref.out_name.split('/').last()
bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' } bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' }
display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name } display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name }
os.mkdir('${display_name}.app') or { panic(err) } os.mkdir('${display_name}.app') or { panic(err.msg) }
os.write_file('${display_name}.app/Info.plist', make_ios_plist(display_name, bundle_id, os.write_file('${display_name}.app/Info.plist', make_ios_plist(display_name, bundle_id,
bundle_name, 1)) or { panic(err) } bundle_name, 1)) or { panic(err.msg) }
} }
b.cc() b.cc()
} }

View File

@ -90,7 +90,7 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) {
if v.pref.is_verbose { if v.pref.is_verbose {
eprintln('>> remove tmp file: $tmpfile') eprintln('>> remove tmp file: $tmpfile')
} }
os.rm(tmpfile) or { panic(err) } os.rm(tmpfile) or { panic(err.msg) }
} }
} }
return return
@ -418,7 +418,7 @@ fn (mut v Builder) setup_output_name() {
println('Building $v.pref.path to $v.pref.out_name ...') println('Building $v.pref.path to $v.pref.out_name ...')
} }
v.pref.cache_manager.save('.description.txt', v.pref.path, '${v.pref.path:-30} @ $v.pref.cache_manager.vopts\n') or { v.pref.cache_manager.save('.description.txt', v.pref.path, '${v.pref.path:-30} @ $v.pref.cache_manager.vopts\n') or {
panic(err) panic(err.msg)
} }
// println('v.table.imports:') // println('v.table.imports:')
// println(v.table.imports) // println(v.table.imports)
@ -469,7 +469,7 @@ fn (mut v Builder) vjs_cc() bool {
} }
} }
// v.out_name_c may be on a different partition than v.out_name // v.out_name_c may be on a different partition than v.out_name
os.mv_by_cp(v.out_name_c, v.pref.out_name) or { panic(err) } os.mv_by_cp(v.out_name_c, v.pref.out_name) or { panic(err.msg) }
return true return true
} }
return false return false
@ -481,7 +481,7 @@ fn (mut v Builder) dump_c_options(all_args []string) {
if v.pref.dump_c_flags == '-' { if v.pref.dump_c_flags == '-' {
print(non_empty_args) print(non_empty_args)
} else { } else {
os.write_file(v.pref.dump_c_flags, non_empty_args) or { panic(err) } os.write_file(v.pref.dump_c_flags, non_empty_args) or { panic(err.msg) }
} }
} }
} }
@ -638,7 +638,7 @@ fn (mut v Builder) cc() {
res := os.exec(cmd) or { res := os.exec(cmd) or {
os.Result{ os.Result{
exit_code: 111 exit_code: 111
output: 'C compilation failed.\n$err' output: 'C compilation failed.\n$err.msg'
} }
} }
util.timing_measure(ccompiler_label) util.timing_measure(ccompiler_label)
@ -709,7 +709,7 @@ fn (mut v Builder) cc() {
obj_file + obj_file +
' /usr/lib/x86_64-linux-gnu/libc.so ' + ' /usr/lib/x86_64-linux-gnu/libc.so ' +
'/usr/lib/x86_64-linux-gnu/crtn.o') or { '/usr/lib/x86_64-linux-gnu/crtn.o') or {
verror(err) verror(err.msg)
return return
} }
println(ress.output) println(ress.output)
@ -759,7 +759,7 @@ fn (mut b Builder) cc_linux_cross() {
b.setup_output_name() b.setup_output_name()
parent_dir := os.vmodules_dir() parent_dir := os.vmodules_dir()
if !os.exists(parent_dir) { if !os.exists(parent_dir) {
os.mkdir(parent_dir) or { panic(err) } os.mkdir(parent_dir) or { panic(err.msg) }
} }
sysroot := os.join_path(os.vmodules_dir(), 'linuxroot') sysroot := os.join_path(os.vmodules_dir(), 'linuxroot')
if !os.is_dir(sysroot) { if !os.is_dir(sysroot) {
@ -819,7 +819,7 @@ fn (mut b Builder) cc_linux_cross() {
} }
res := os.exec(linker_cmd) or { res := os.exec(linker_cmd) or {
println('Cross compilation for Linux failed (second step, lld).') println('Cross compilation for Linux failed (second step, lld).')
verror(err) verror(err.msg)
return return
} }
if res.exit_code != 0 { if res.exit_code != 0 {
@ -963,7 +963,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
// for example thirdparty\tcc\lib\openlibm.o // for example thirdparty\tcc\lib\openlibm.o
// the best we can do for them is just copy them, // the best we can do for them is just copy them,
// and hope that they work with any compiler... // and hope that they work with any compiler...
os.cp(obj_path, opath) or { panic(err) } os.cp(obj_path, opath) or { panic(err.msg) }
return return
} }
println('$obj_path not found, building it in $opath ...') println('$obj_path not found, building it in $opath ...')
@ -984,7 +984,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
} }
res := os.exec(cmd) or { res := os.exec(cmd) or {
eprintln('exec failed for thirdparty object build cmd:\n$cmd') eprintln('exec failed for thirdparty object build cmd:\n$cmd')
verror(err) verror(err.msg)
return return
} }
os.chdir(current_folder) os.chdir(current_folder)
@ -994,7 +994,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF
return return
} }
v.pref.cache_manager.save('.description.txt', obj_path, '${obj_path:-30} @ $cmd\n') or { v.pref.cache_manager.save('.description.txt', obj_path, '${obj_path:-30} @ $cmd\n') or {
panic(err) panic(err.msg)
} }
println(res.output) println(res.output)
} }

View File

@ -29,7 +29,7 @@ pub fn compile(command string, pref &pref.Preferences) {
} }
os.is_writable_folder(output_folder) or { os.is_writable_folder(output_folder) or {
// An early error here, is better than an unclear C error later: // An early error here, is better than an unclear C error later:
verror(err) verror(err.msg)
exit(1) exit(1)
} }
// Construct the V object from command line arguments // Construct the V object from command line arguments
@ -93,12 +93,12 @@ fn (mut b Builder) run_compiled_executable_and_exit() {
} }
if b.pref.os == .ios { if b.pref.os == .ios {
device := '"iPhone SE (2nd generation)"' device := '"iPhone SE (2nd generation)"'
os.exec('xcrun simctl boot $device') or { panic(err) } os.exec('xcrun simctl boot $device') or { panic(err.msg) }
bundle_name := b.pref.out_name.split('/').last() bundle_name := b.pref.out_name.split('/').last()
display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name } display_name := if b.pref.display_name != '' { b.pref.display_name } else { bundle_name }
os.exec('xcrun simctl install $device ${display_name}.app') or { panic(err) } os.exec('xcrun simctl install $device ${display_name}.app') or { panic(err.msg) }
bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' } bundle_id := if b.pref.bundle_id != '' { b.pref.bundle_id } else { 'app.vlang.$bundle_name' }
os.exec('xcrun simctl launch $device $bundle_id') or { panic(err) } os.exec('xcrun simctl launch $device $bundle_id') or { panic(err.msg) }
} else { } else {
exefile := os.real_path(b.pref.out_name) exefile := os.real_path(b.pref.out_name)
mut cmd := '"$exefile"' mut cmd := '"$exefile"'
@ -133,7 +133,7 @@ fn (mut v Builder) cleanup_run_executable_after_exit(exefile string) {
} }
if os.is_file(exefile) { if os.is_file(exefile) {
v.pref.vrun_elog('remove run executable: $exefile') v.pref.vrun_elog('remove run executable: $exefile')
os.rm(exefile) or { panic(err) } os.rm(exefile) or { panic(err.msg) }
} }
} }

View File

@ -34,8 +34,8 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) {
b.out_name_js = out_file b.out_name_js = out_file
b.info('build_js($out_file)') b.info('build_js($out_file)')
output := b.gen_js(v_files) output := b.gen_js(v_files)
mut f := os.create(out_file) or { panic(err) } mut f := os.create(out_file) or { panic(err.msg) }
f.writeln(output) or { panic(err) } f.writeln(output) or { panic(err.msg) }
f.close() f.close()
} }
@ -58,7 +58,7 @@ fn (mut b Builder) run_js() {
cmd := 'node ' + b.pref.out_name + '.js' cmd := 'node ' + b.pref.out_name + '.js'
res := os.exec(cmd) or { res := os.exec(cmd) or {
println('JS compilation failed.') println('JS compilation failed.')
verror(err) verror(err.msg)
return return
} }
println(res.output) println(res.output)

View File

@ -329,7 +329,7 @@ pub fn (mut v Builder) cc_msvc() {
// println(res) // println(res)
// println('C OUTPUT:') // println('C OUTPUT:')
// Always remove the object file - it is completely unnecessary // Always remove the object file - it is completely unnecessary
os.rm(out_name_obj) or { panic(err) } os.rm(out_name_obj) or { panic(err.msg) }
} }
fn (mut v Builder) build_thirdparty_obj_file_with_msvc(path string, moduleflags []cflag.CFlag) { fn (mut v Builder) build_thirdparty_obj_file_with_msvc(path string, moduleflags []cflag.CFlag) {
@ -369,7 +369,7 @@ fn (mut v Builder) build_thirdparty_obj_file_with_msvc(path string, moduleflags
} }
res := os.exec(cmd) or { res := os.exec(cmd) or {
println('msvc: failed to execute msvc compiler (to build a thirdparty object); cmd: $cmd') println('msvc: failed to execute msvc compiler (to build a thirdparty object); cmd: $cmd')
verror(err) verror(err.msg)
return return
} }
if res.exit_code != 0 { if res.exit_code != 0 {

View File

@ -318,6 +318,8 @@ pub fn (mut c Checker) fail_if_not_rlocked(expr ast.Expr, what string) {
} }
pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.Type { pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.Type {
inside_println_arg_save := c.inside_println_arg
c.inside_println_arg = true
for i, expr in node.exprs { for i, expr in node.exprs {
ftyp := c.expr(expr) ftyp := c.expr(expr)
if ftyp.has_flag(.shared_f) { if ftyp.has_flag(.shared_f) {
@ -365,6 +367,7 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T
c.error('cannot call `str()` method recursively', expr.position()) c.error('cannot call `str()` method recursively', expr.position())
} }
} }
c.inside_println_arg = inside_println_arg_save
return table.string_type return table.string_type
} }

View File

@ -2972,7 +2972,7 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
if array_init.has_default { if array_init.has_default {
default_typ := c.expr(array_init.default_expr) default_typ := c.expr(array_init.default_expr)
c.check_expected(default_typ, array_init.elem_type) or { c.check_expected(default_typ, array_init.elem_type) or {
c.error(err, array_init.default_expr.position()) c.error(err.msg, array_init.default_expr.position())
} }
} }
if sym.kind == .sum_type { if sym.kind == .sum_type {
@ -3459,7 +3459,7 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
mut flag := node.main mut flag := node.main
if flag.contains('@VROOT') { if flag.contains('@VROOT') {
vroot := util.resolve_vroot(flag, c.file.path) or { vroot := util.resolve_vroot(flag, c.file.path) or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
node.val = 'include $vroot' node.val = 'include $vroot'
@ -3468,7 +3468,7 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
} }
if flag.contains('\$env(') { if flag.contains('\$env(') {
env := util.resolve_env_value(flag, true) or { env := util.resolve_env_value(flag, true) or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
node.main = env node.main = env
@ -3486,15 +3486,15 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
'--cflags --libs $node.main'.split(' ') '--cflags --libs $node.main'.split(' ')
} }
mut m := pkgconfig.main(args) or { mut m := pkgconfig.main(args) or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
cflags := m.run() or { cflags := m.run() or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
c.table.parse_cflag(cflags, c.mod, c.pref.compile_defines_all) or { c.table.parse_cflag(cflags, c.mod, c.pref.compile_defines_all) or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
} else if node.kind == 'flag' { } else if node.kind == 'flag' {
@ -3503,13 +3503,13 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
// expand `@VROOT` to its absolute path // expand `@VROOT` to its absolute path
if flag.contains('@VROOT') { if flag.contains('@VROOT') {
flag = util.resolve_vroot(flag, c.file.path) or { flag = util.resolve_vroot(flag, c.file.path) or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
} }
if flag.contains('\$env(') { if flag.contains('\$env(') {
flag = util.resolve_env_value(flag, true) or { flag = util.resolve_env_value(flag, true) or {
c.error(err, node.pos) c.error(err.msg, node.pos)
return return
} }
} }
@ -3519,7 +3519,9 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) {
} }
} }
// println('adding flag "$flag"') // println('adding flag "$flag"')
c.table.parse_cflag(flag, c.mod, c.pref.compile_defines_all) or { c.error(err, node.pos) } c.table.parse_cflag(flag, c.mod, c.pref.compile_defines_all) or {
c.error(err.msg, node.pos)
}
} else { } else {
if node.kind != 'define' { if node.kind != 'define' {
c.error('expected `#define`, `#flag`, `#include` or `#pkgconfig` not $node.val', c.error('expected `#define`, `#flag`, `#include` or `#pkgconfig` not $node.val',
@ -3654,7 +3656,7 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
return node.typ.to_ptr() return node.typ.to_ptr()
} }
ast.Assoc { ast.Assoc {
v := node.scope.find_var(node.var_name) or { panic(err) } v := node.scope.find_var(node.var_name) or { panic(err.msg) }
for i, _ in node.fields { for i, _ in node.fields {
c.expr(node.exprs[i]) c.expr(node.exprs[i])
} }
@ -3951,7 +3953,7 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) table.Type {
node.sym = c.table.get_type_symbol(c.unwrap_generic(c.expr(node.left))) node.sym = c.table.get_type_symbol(c.unwrap_generic(c.expr(node.left)))
if node.is_env { if node.is_env {
env_value := util.resolve_env_value("\$env('$node.args_var')", false) or { env_value := util.resolve_env_value("\$env('$node.args_var')", false) or {
c.error(err, node.env_pos) c.error(err.msg, node.env_pos)
return table.string_type return table.string_type
} }
node.env_value = env_value node.env_value = env_value
@ -5039,7 +5041,7 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
left_type := c.expr(cond.left) left_type := c.expr(cond.left)
right_type := c.expr(cond.right) right_type := c.expr(cond.right)
expr := c.find_definition(cond.left) or { expr := c.find_definition(cond.left) or {
c.error(err, cond.left.pos) c.error(err.msg, cond.left.pos)
return false return false
} }
if !c.check_types(right_type, left_type) { if !c.check_types(right_type, left_type) {
@ -5089,7 +5091,7 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
return false return false
} }
expr := c.find_obj_definition(cond.obj) or { expr := c.find_obj_definition(cond.obj) or {
c.error(err, cond.pos) c.error(err.msg, cond.pos)
return false return false
} }
if !c.check_types(typ, table.bool_type) { if !c.check_types(typ, table.bool_type) {

View File

@ -1,7 +1,7 @@
vlib/v/checker/tests/return_optional_err.vv:4:13: error: cannot use `?string` as type `string` in return argument vlib/v/checker/tests/return_optional_err.vv:4:13: error: cannot use `?string` as type `string` in return argument
2 | 2 |
3 | fn my_func() string { 3 | fn my_func() string {
4 | return os.read_file('/some/file/that/exists.txt') or {panic(err)} 4 | return os.read_file('/some/file/that/exists.txt') or { panic(err.msg) }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 | } 5 | }
6 | 6 |

View File

@ -1,7 +1,7 @@
import os import os
fn my_func() string { fn my_func() string {
return os.read_file('/some/file/that/exists.txt') or {panic(err)} return os.read_file('/some/file/that/exists.txt') or { panic(err.msg) }
} }
fn main() { fn main() {

View File

@ -239,14 +239,14 @@ fn (mut task TaskDescription) execute() {
} }
program := task.path program := task.path
cli_cmd := '$task.vexe $task.voptions $program' cli_cmd := '$task.vexe $task.voptions $program'
res := os.exec(cli_cmd) or { panic(err) } res := os.exec(cli_cmd) or { panic(err.msg) }
expected_out_path := program.replace('.vv', '') + task.result_extension expected_out_path := program.replace('.vv', '') + task.result_extension
task.expected_out_path = expected_out_path task.expected_out_path = expected_out_path
task.cli_cmd = cli_cmd task.cli_cmd = cli_cmd
if should_autofix && !os.exists(expected_out_path) { if should_autofix && !os.exists(expected_out_path) {
os.write_file(expected_out_path, '') or { panic(err) } os.write_file(expected_out_path, '') or { panic(err.msg) }
} }
mut expected := os.read_file(expected_out_path) or { panic(err) } mut expected := os.read_file(expected_out_path) or { panic(err.msg) }
task.expected = clean_line_endings(expected) task.expected = clean_line_endings(expected)
task.found___ = clean_line_endings(res.output) task.found___ = clean_line_endings(res.output)
$if windows { $if windows {
@ -257,7 +257,7 @@ fn (mut task TaskDescription) execute() {
if task.expected != task.found___ { if task.expected != task.found___ {
task.is_error = true task.is_error = true
if should_autofix { if should_autofix {
os.write_file(expected_out_path, res.output) or { panic(err) } os.write_file(expected_out_path, res.output) or { panic(err.msg) }
} }
} }
} }
@ -279,7 +279,7 @@ fn diff_content(s1 string, s2 string) {
} }
fn get_tests_in_dir(dir string, is_module bool) []string { fn get_tests_in_dir(dir string, is_module bool) []string {
files := os.ls(dir) or { panic(err) } files := os.ls(dir) or { panic(err.msg) }
mut tests := files.clone() mut tests := files.clone()
if !is_module { if !is_module {
tests = files.filter(it.ends_with('.vv')) tests = files.filter(it.ends_with('.vv'))

View File

@ -353,7 +353,7 @@ pub fn (mut d Doc) generate() ? {
os.real_path(os.dir(d.base_path)) os.real_path(os.dir(d.base_path))
} }
d.is_vlib = 'vlib' !in d.base_path d.is_vlib = 'vlib' !in d.base_path
project_files := os.ls(d.base_path) or { return error_with_code(err, 0) } project_files := os.ls(d.base_path) or { return err }
v_files := d.prefs.should_compile_filtered_files(d.base_path, project_files) v_files := d.prefs.should_compile_filtered_files(d.base_path, project_files)
if v_files.len == 0 { if v_files.len == 0 {
return error_with_code('vdoc: No valid V files were found.', 1) return error_with_code('vdoc: No valid V files were found.', 1)

View File

@ -67,7 +67,7 @@ fn test_fmt() {
continue continue
} }
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename') vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename')
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) } os.write_file(vfmt_result_file, result_ocontent) or { panic(err.msg) }
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file)) eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue continue
} }

View File

@ -59,7 +59,7 @@ fn test_fmt() {
continue continue
} }
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename') vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename')
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) } os.write_file(vfmt_result_file, result_ocontent) or { panic(err.msg) }
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file)) eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue continue
} }

View File

@ -57,7 +57,7 @@ fn test_vlib_fmt() {
continue continue
} }
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename') vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_$ifilename')
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) } os.write_file(vfmt_result_file, result_ocontent) or { panic(err.msg) }
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file)) eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue continue
} }

View File

@ -16,7 +16,7 @@ fn get_val_from_chan(ch chan i64) ?i64 {
fn get_val_from_chan2(ch chan i64) ?i64 { fn get_val_from_chan2(ch chan i64) ?i64 {
r := <-ch or { r := <-ch or {
println('error') println('error')
return error(err) return err
} }
return r return r
} }

View File

@ -34,13 +34,13 @@ fn branches_are_struct_inits() {
fn branches_are_call_exprs_with_or_blocks() { fn branches_are_call_exprs_with_or_blocks() {
match 'a' { match 'a' {
'b' { foo() or { panic(err) } } 'b' { foo() or { panic(err.msg) } }
} }
match 'a' { match 'a' {
'b' { 'b' {
foo() or { foo() or {
// do stuff // do stuff
panic(err) panic(err.msg)
} }
} }
} }
@ -48,7 +48,7 @@ fn branches_are_call_exprs_with_or_blocks() {
'b' { 'b' {
foo() or { foo() or {
another_stmt() another_stmt()
panic(err) panic(err.msg)
} }
} }
} }

View File

@ -648,7 +648,9 @@ static inline $opt_el_type __Option2_${styp}_popval($styp ch) {
$opt_el_type _tmp = {0}; $opt_el_type _tmp = {0};
if (sync__Channel_try_pop_priv(ch, _tmp.data, false)) { if (sync__Channel_try_pop_priv(ch, _tmp.data, false)) {
Option2 _tmp2 = error2(_SLIT("channel closed")); Option2 _tmp2 = error2(_SLIT("channel closed"));
return *($opt_el_type*)&_tmp2; $opt_el_type _tmp3;
memcpy(&_tmp3, &_tmp2, sizeof(Option2));
return _tmp3;
} }
return _tmp; return _tmp;
}') }')
@ -662,7 +664,9 @@ fn (mut g Gen) register_chan_push_optional_call(el_type string, styp string) {
static inline Option2_void __Option2_${styp}_pushval($styp ch, $el_type e) { static inline Option2_void __Option2_${styp}_pushval($styp ch, $el_type e) {
if (sync__Channel_try_push_priv(ch, &e, false)) { if (sync__Channel_try_push_priv(ch, &e, false)) {
Option2 _tmp2 = error2(_SLIT("channel closed")); Option2 _tmp2 = error2(_SLIT("channel closed"));
return *(Option2_void*)&_tmp2; Option2_void _tmp3;
memcpy(&_tmp3, &_tmp2, sizeof(Option2));
return _tmp3;
} }
return (Option2_void){0}; return (Option2_void){0};
}') }')
@ -5571,7 +5575,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
} }
} else if or_block.kind == .propagate { } else if or_block.kind == .propagate {
if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.name == 'main.main') { if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.name == 'main.main') {
// In main(), an `opt()?` call is sugar for `opt() or { panic(err) }` // In main(), an `opt()?` call is sugar for `opt() or { panic(err.msg) }`
if g.pref.is_debug { if g.pref.is_debug {
paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos) paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos)
g.writeln('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ${cvar_name}.err.msg );') g.writeln('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ${cvar_name}.err.msg );')
@ -5580,7 +5584,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
} }
} else { } else {
// In ordinary functions, `opt()?` call is sugar for: // In ordinary functions, `opt()?` call is sugar for:
// `opt() or { return error(err) }` // `opt() or { return err }`
// Since we *do* return, first we have to ensure that // Since we *do* return, first we have to ensure that
// the defered statements are generated. // the defered statements are generated.
g.write_defer_stmts() g.write_defer_stmts()

View File

@ -18,7 +18,7 @@ fn test_c_files() {
vroot := os.dir(vexe) vroot := os.dir(vexe)
for i in 1 .. (nr_tests + 1) { for i in 1 .. (nr_tests + 1) {
path := '$vroot/vlib/v/gen/tests/${i}.vv' path := '$vroot/vlib/v/gen/tests/${i}.vv'
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or { panic(err) } ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or { panic(err.msg) }
mut b := builder.new_builder(&pref.Preferences{}) mut b := builder.new_builder(&pref.Preferences{})
b.module_search_paths = ['$vroot/vlib/v/gen/tests/'] b.module_search_paths = ['$vroot/vlib/v/gen/tests/']
mut res := b.gen_c([path]).after('#endbuiltin') mut res := b.gen_c([path]).after('#endbuiltin')

View File

@ -237,7 +237,7 @@ fn (mut g Gen) comp_if_cond(cond ast.Expr) bool {
} }
ast.PostfixExpr { ast.PostfixExpr {
ifdef := g.comp_if_to_ifdef((cond.expr as ast.Ident).name, true) or { ifdef := g.comp_if_to_ifdef((cond.expr as ast.Ident).name, true) or {
verror(err) verror(err.msg)
return false return false
} }
g.write('defined($ifdef)') g.write('defined($ifdef)')

View File

@ -15,7 +15,7 @@ const there_is_node_available = is_nodejs_working()
fn test_example_compilation() { fn test_example_compilation() {
vexe := os.getenv('VEXE') vexe := os.getenv('VEXE')
os.chdir(os.dir(vexe)) os.chdir(os.dir(vexe))
os.mkdir_all(output_dir) or { panic(err) } os.mkdir_all(output_dir) or { panic(err.msg) }
files := find_test_files() files := find_test_files()
for file in files { for file in files {
path := os.join_path(test_dir, file) path := os.join_path(test_dir, file)
@ -40,7 +40,7 @@ fn test_example_compilation() {
} }
fn find_test_files() []string { fn find_test_files() []string {
files := os.ls(test_dir) or { panic(err) } files := os.ls(test_dir) or { panic(err.msg) }
// The life example never exits, so tests would hang with it, skip // The life example never exits, so tests would hang with it, skip
mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v') mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v')
tests.sort() tests.sort()

View File

@ -88,7 +88,7 @@ fn main() {
println(message) println(message)
}) })
hl.raw_js_log() hl.raw_js_log()
propagation() or { println(err) } propagation() or { println(err.msg) }
} }
fn anon_consumer(greeting string, anon fn (message string)) { fn anon_consumer(greeting string, anon fn (message string)) {

View File

@ -99,7 +99,7 @@ pub fn (mut g Gen) generate_elf_footer() {
// -5 is for "e8 00 00 00 00" // -5 is for "e8 00 00 00 00"
g.write32_at(g.code_start_pos + 1, int(g.main_fn_addr - g.code_start_pos) - 5) g.write32_at(g.code_start_pos + 1, int(g.main_fn_addr - g.code_start_pos) - 5)
// Create the binary // Create the binary
mut f := os.create(g.out_name) or { panic(err) } mut f := os.create(g.out_name) or { panic(err.msg) }
os.chmod(g.out_name, 0o775) // make it an executable os.chmod(g.out_name, 0o775) // make it an executable
unsafe { f.write_bytes(g.buf.data, g.buf.len) } unsafe { f.write_bytes(g.buf.data, g.buf.len) }
f.close() f.close()

View File

@ -15,10 +15,10 @@ fn test_x64() {
vexe := os.getenv('VEXE') vexe := os.getenv('VEXE')
vroot := os.dir(vexe) vroot := os.dir(vexe)
dir := os.join_path(vroot, 'vlib/v/gen/x64/tests') dir := os.join_path(vroot, 'vlib/v/gen/x64/tests')
files := os.ls(dir) or { panic(err) } files := os.ls(dir) or { panic(err.msg) }
// //
wrkdir := os.join_path(os.temp_dir(), 'vtests', 'x64') wrkdir := os.join_path(os.temp_dir(), 'vtests', 'x64')
os.mkdir_all(wrkdir) or { panic(err) } os.mkdir_all(wrkdir) or { panic(err.msg) }
os.chdir(wrkdir) os.chdir(wrkdir)
tests := files.filter(it.ends_with('.vv')) tests := files.filter(it.ends_with('.vv'))
if tests.len == 0 { if tests.len == 0 {
@ -46,7 +46,7 @@ fn test_x64() {
eprintln(res.output) eprintln(res.output)
continue continue
} }
mut expected := os.read_file('$dir/${test}.out') or { panic(err) } mut expected := os.read_file('$dir/${test}.out') or { panic(err.msg) }
expected = expected.trim_right('\r\n').replace('\r\n', '\n') expected = expected.trim_right('\r\n').replace('\r\n', '\n')
mut found := res.output.trim_right('\r\n').replace('\r\n', '\n') mut found := res.output.trim_right('\r\n').replace('\r\n', '\n')
found = found.trim_space() found = found.trim_space()

View File

@ -44,7 +44,7 @@ const (
) )
fn get_source_template() string { fn get_source_template() string {
src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or { panic(err) } src := os.read_file(os.join_path(os.dir(@FILE), 'live_test_template.vv')) or { panic(err.msg) }
return src.replace('#OUTPUT_FILE#', output_file) return src.replace('#OUTPUT_FILE#', output_file)
} }
@ -60,8 +60,8 @@ fn atomic_write_source(source string) {
// NB: here wrtiting is done in 2 steps, since os.write_file can take some time, // NB: here wrtiting is done in 2 steps, since os.write_file can take some time,
// during which the file will be modified, but it will still be not completely written. // during which the file will be modified, but it will still be not completely written.
// The os.mv after that, guarantees that the reloader will see a complete valid V program. // The os.mv after that, guarantees that the reloader will see a complete valid V program.
os.write_file(tmp_file, source) or { panic(err) } os.write_file(tmp_file, source) or { panic(err.msg) }
os.mv(tmp_file, source_file) or { panic(err) } os.mv(tmp_file, source_file) or { panic(err.msg) }
} }
// //

View File

@ -152,7 +152,7 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
// for handling them, and should be removed when we do (the general solution is also needed for vfmt) // for handling them, and should be removed when we do (the general solution is also needed for vfmt)
// println('parse_file("$path")') // println('parse_file("$path")')
// text := os.read_file(path) or { // text := os.read_file(path) or {
// panic(err) // panic(err.msg)
// } // }
mut p := Parser{ mut p := Parser{
scanner: scanner.new_scanner_file(path, comments_mode, pref) scanner: scanner.new_scanner_file(path, comments_mode, pref)

View File

@ -83,7 +83,7 @@ pub fn (mut m Main) run() ?string {
for arg in opt.args { for arg in opt.args {
mut pcdep := load(arg, options) or { mut pcdep := load(arg, options) or {
if !opt.exists { if !opt.exists {
return error(err) return err
} }
continue continue
} }

View File

@ -245,7 +245,7 @@ pub fn load(pkgname string, options Options) ?&PkgConfig {
options: options options: options
} }
pc.load_paths() pc.load_paths()
file := pc.resolve(pkgname) or { return error(err) } file := pc.resolve(pkgname) or { return err }
if !pc.parse(file) { if !pc.parse(file) {
return error('file "$file" could not be parsed') return error('file "$file" could not be parsed')
} }

Some files were not shown because too many files have changed in this diff Show More