From d63b7bc35aca7e992edc8d610fb625c55a541585 Mon Sep 17 00:00:00 2001 From: spaceface Date: Sun, 28 Feb 2021 21:20:21 +0100 Subject: [PATCH] all: update repo to use the new error handling syntax (#8950) --- cmd/tools/fast/fast.v | 4 +- cmd/tools/gen_vc.v | 8 +- cmd/tools/missdoc.v | 2 +- cmd/tools/modules/scripting/scripting.v | 6 +- cmd/tools/modules/testing/common.v | 10 +- cmd/tools/oldv.v | 2 +- cmd/tools/test_if_v_test_system_works.v | 10 +- cmd/tools/vbin2v.v | 2 +- cmd/tools/vbuild-tools.v | 4 +- cmd/tools/vcheck-md.v | 4 +- cmd/tools/vcreate.v | 12 +- cmd/tools/vdoc/html.v | 4 +- cmd/tools/vdoc/vdoc.v | 12 +- cmd/tools/vfmt.v | 8 +- cmd/tools/vpm.v | 10 +- cmd/tools/vrepl.v | 8 +- cmd/tools/vself.v | 6 +- cmd/tools/vsetup-freetype.v | 2 +- cmd/tools/vsymlink.v | 18 +-- cmd/tools/vtest-parser.v | 4 +- cmd/tools/vup.v | 10 +- cmd/tools/vvet/vet_test.v | 6 +- doc/docs.md | 10 +- examples/database/orm.v | 2 +- examples/database/pg/customer.v | 2 +- examples/flappylearning/game.v | 8 +- examples/path_tracing.v | 10 +- examples/process/command.v | 2 +- examples/process/execve.v | 2 +- examples/process/process_script.v | 2 +- examples/regex/regex_example.v | 6 +- examples/templates/templates.v | 8 +- examples/term.ui/text_editor.v | 4 +- examples/ttf_font/example_ttf.v | 2 +- examples/v_script.vsh | 4 +- examples/websocket/client-server/server.v | 2 +- examples/websocket/ping.v | 2 +- tutorials/code/blog/blog.v | 2 +- vlib/builtin/bare/syscallwrapper_test.v | 2 +- vlib/builtin/js/builtin.v | 42 +++--- vlib/cli/command.v | 4 +- vlib/cli/command_test.v | 2 +- vlib/cli/flag_test.v | 78 +++++------ vlib/crypto/md5/md5.v | 4 +- vlib/crypto/sha1/sha1.v | 8 +- vlib/crypto/sha256/sha256.v | 10 +- vlib/crypto/sha512/sha512.v | 14 +- vlib/dl/example/use_test.v | 2 +- vlib/encoding/csv/reader.v | 4 +- vlib/gg/gg.v | 6 +- vlib/io/os_file_reader_test.v | 2 +- vlib/io/util/util_test.v | 2 +- vlib/json/json_test.v | 2 +- vlib/log/log.v | 2 +- vlib/net/ftp/ftp.v | 2 +- vlib/net/ftp/ftp_test.v | 4 +- vlib/net/html/dom.v | 2 +- vlib/net/html/parser.v | 2 +- vlib/net/http/download.v | 2 +- vlib/net/http/http_httpbin_test.v | 14 +- vlib/net/http/http_test.v | 6 +- vlib/net/tcp_simple_client_server_test.v | 6 +- vlib/net/tcp_test.v | 4 +- vlib/net/unix/unix_test.v | 4 +- vlib/orm/orm_test.v | 4 +- vlib/os/inode_test.v | 6 +- vlib/os/os.v | 6 +- vlib/os/os_test.v | 126 +++++++++--------- vlib/readline/readline_test.v | 2 +- vlib/semver/range.v | 4 +- vlib/sqlite/sqlite_test.v | 6 +- vlib/term/ui/termios_nix.c.v | 2 +- vlib/v/builder/builder.v | 4 +- vlib/v/builder/c.v | 8 +- vlib/v/builder/cc.v | 22 +-- vlib/v/builder/compile.v | 10 +- vlib/v/builder/js.v | 6 +- vlib/v/builder/msvc.v | 4 +- vlib/v/checker/check_types.v | 3 + vlib/v/checker/checker.v | 28 ++-- vlib/v/checker/tests/return_optional_err.out | 2 +- vlib/v/checker/tests/return_optional_err.vv | 2 +- vlib/v/compiler_errors_test.v | 10 +- vlib/v/doc/doc.v | 2 +- vlib/v/fmt/fmt_keep_test.v | 2 +- vlib/v/fmt/fmt_test.v | 2 +- vlib/v/fmt/fmt_vlib_test.v | 2 +- vlib/v/fmt/tests/chan_ops_keep.vv | 2 +- vlib/v/fmt/tests/match_keep.vv | 6 +- vlib/v/gen/c/cgen.v | 12 +- vlib/v/gen/c/cgen_test.v | 2 +- vlib/v/gen/c/comptime.v | 2 +- vlib/v/gen/js/jsgen_test.v | 4 +- vlib/v/gen/js/tests/js.v | 2 +- vlib/v/gen/x64/elf.v | 2 +- vlib/v/gen/x64/tests/x64_test.v | 6 +- vlib/v/live/live_test.v | 6 +- vlib/v/parser/parser.v | 2 +- vlib/v/pkgconfig/main.v | 2 +- vlib/v/pkgconfig/pkgconfig.v | 2 +- vlib/v/pref/pref.v | 2 +- vlib/v/table/table.v | 2 +- .../v/tests/anon_fn_returning_question_test.v | 2 +- vlib/v/tests/inout/compiler_test.v | 10 +- vlib/v/tests/inout/os.vv | 2 +- .../vmodules_overrides_test.v | 4 +- vlib/v/tests/option_test.v | 4 +- vlib/v/tests/orm_sub_struct_test.v | 4 +- vlib/v/tests/prod_test.v | 2 +- vlib/v/tests/repl/repl_test.v | 16 +-- vlib/v/tests/repl/run.v | 2 +- vlib/v/tests/repl/runner/runner.v | 14 +- vlib/v/tests/run_v_code_from_stdin_test.v | 4 +- vlib/v/tests/valgrind/valgrind_test.v | 4 +- vlib/v/tests/vargs_empty_param_test.v | 2 +- vlib/v/tests/vmod_parser_test.v | 2 +- vlib/v/util/diff.v | 8 +- vlib/v/util/util.v | 8 +- vlib/v/vcache/vcache.v | 8 +- vlib/vweb/assets/assets.v | 6 +- vlib/vweb/assets/assets_test.v | 6 +- vlib/vweb/tests/vweb_test.v | 28 ++-- vlib/vweb/vweb.v | 2 +- vlib/x/ttf/common.v | 12 +- vlib/x/ttf/ttf_test.v | 6 +- vlib/x/websocket/io.v | 6 +- vlib/x/websocket/message.v | 2 +- .../tests/autobahn/autobahn_client.v | 2 +- .../tests/autobahn/autobahn_client_wss.v | 2 +- .../tests/autobahn/autobahn_server.v | 4 +- .../autobahn/local_run/autobahn_client.v | 2 +- .../autobahn/local_run/autobahn_client_wss.v | 2 +- vlib/x/websocket/websocket_client.v | 4 +- vlib/x/websocket/websocket_server.v | 4 +- vlib/x/websocket/websocket_test.v | 4 +- 135 files changed, 487 insertions(+), 468 deletions(-) diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index 2b6ff32313..99292c233c 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -81,7 +81,7 @@ fn main() { } 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') } @@ -111,7 +111,7 @@ fn measure(cmd string, description string) 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() if lines.len != 3 { return 0, 0, 0 diff --git a/cmd/tools/gen_vc.v b/cmd/tools/gen_vc.v index dac8a9ded8..3f2033cee3 100644 --- a/cmd/tools/gen_vc.v +++ b/cmd/tools/gen_vc.v @@ -210,7 +210,7 @@ fn (mut gen_vc GenVC) generate() { // check if gen_vc dir exists if !os.is_dir(gen_vc.options.work_dir) { // 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 if !os.is_dir(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_vc := git_log_vc.find_between('Date:', '\n').trim_space() // parse time as string to time.Time - last_commit_time_v := time.parse(ts_v) or { panic(err) } - last_commit_time_vc := time.parse(ts_vc) 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.msg) } // 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 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') r := os.exec(cmd) or { 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 gen_vc.purge_repos() gen_vc.gen_error = true diff --git a/cmd/tools/missdoc.v b/cmd/tools/missdoc.v index d6892eb90b..d5b40fbf0d 100644 --- a/cmd/tools/missdoc.v +++ b/cmd/tools/missdoc.v @@ -55,7 +55,7 @@ fn report_undocumented_functions_in_path(opt Options, path 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') mut info := []UndocumentedFN{} for i, line in lines { diff --git a/cmd/tools/modules/scripting/scripting.v b/cmd/tools/modules/scripting/scripting.v index 2e406a1ec4..ce06294979 100644 --- a/cmd/tools/modules/scripting/scripting.v +++ b/cmd/tools/modules/scripting/scripting.v @@ -53,9 +53,9 @@ pub fn rmrf(path string) { verbose_trace(@FN, 'rm -rf $path') if os.exists(path) { if os.is_dir(path) { - os.rmdir_all(path) or { panic(err) } + os.rmdir_all(path) or { panic(err.msg) } } 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) x := os.exec(cmd) or { verbose_trace(@FN, '## failed.') - return error(err) + return err } verbose_trace_exec_result(x) return x diff --git a/cmd/tools/modules/testing/common.v b/cmd/tools/modules/testing/common.v index 3cf4e846bf..673ea63aec 100644 --- a/cmd/tools/modules/testing/common.v +++ b/cmd/tools/modules/testing/common.v @@ -221,7 +221,7 @@ pub fn (mut ts TestSession) test() { // cleanup generated .tmp.c files after successfull tests: if ts.benchmark.nfail == 0 { 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) if os.exists(generated_binary_fpath) { 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] @@ -308,7 +308,7 @@ fn worker_trunner(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { } if os.exists(generated_binary_fpath) { 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 @@ -358,7 +358,7 @@ pub fn prepare_test_session(zargs string, folder string, oskipped []string, main 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 } start := c[0..maxc] if start.contains('module ') && !start.contains('module main') { @@ -436,7 +436,7 @@ pub fn header(msg string) { pub fn setup_new_vtmp_folder() string { now := time.sys_mono_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) return new_vtmp_dir } diff --git a/cmd/tools/oldv.v b/cmd/tools/oldv.v index afdbb8f121..c295f91079 100644 --- a/cmd/tools/oldv.v +++ b/cmd/tools/oldv.v @@ -101,7 +101,7 @@ fn main() { scripting.cprintln('# checkout folder: $context.path_v') if context.cmd_to_run.len > 0 { 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:') println(cmdres.output) diff --git a/cmd/tools/test_if_v_test_system_works.v b/cmd/tools/test_if_v_test_system_works.v index 11596cee27..e57d5814f1 100644 --- a/cmd/tools/test_if_v_test_system_works.v +++ b/cmd/tools/test_if_v_test_system_works.v @@ -28,16 +28,16 @@ fn get_vexe_path() string { fn new_tdir() string { tdir_ := os.join_path(os.temp_dir(), rand.ulid()) 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) return tdir_ } fn cleanup_tdir() { println('... removing tdir: $tdir') - os.rmdir_all(tdir) or { panic(err) } + os.rmdir_all(tdir) or { panic(err.msg) } } fn main() { @@ -55,7 +55,7 @@ fn main() { fn check_ok(cmd string) string { 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 { eprintln('> check_ok failed.\n$res.output') exit(1) @@ -65,7 +65,7 @@ fn check_ok(cmd string) string { fn check_fail(cmd string) string { 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 { eprintln('> check_fail succeeded, but it should have failed.\n$res.output') exit(1) diff --git a/cmd/tools/vbin2v.v b/cmd/tools/vbin2v.v index 86f19d2fff..f2ee1c3337 100644 --- a/cmd/tools/vbin2v.v +++ b/cmd/tools/vbin2v.v @@ -108,7 +108,7 @@ fn main() { exit(0) } files := fp.finalize() or { - eprintln('Error: ' + err) + eprintln('Error: $err') exit(1) } real_files := files.filter(it != 'bin2v') diff --git a/cmd/tools/vbuild-tools.v b/cmd/tools/vbuild-tools.v index 3a06e7479f..3ad76af562 100644 --- a/cmd/tools/vbuild-tools.v +++ b/cmd/tools/vbuild-tools.v @@ -55,11 +55,11 @@ fn main() { // tpath := os.join_path(session.vtmp_dir, texe) 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 } os.mv_by_cp(tpath, os.join_path(tfolder, texe)) or { - if !err.contains('vbuild-tools') { + if !err.msg.contains('vbuild-tools') { eprintln(err) } continue diff --git a/cmd/tools/vcheck-md.v b/cmd/tools/vcheck-md.v index 5fcba74c2c..b8ad64d650 100644 --- a/cmd/tools/vcheck-md.v +++ b/cmd/tools/vcheck-md.v @@ -244,7 +244,7 @@ fn (mut f MDFile) check_examples() (int, int) { mut should_cleanup_vfile := true // eprintln('>>> checking example $vfile ...') 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(' ') nofmt := 'nofmt' in acommands for command in acommands { @@ -331,7 +331,7 @@ fn (mut f MDFile) check_examples() (int, int) { } } if should_cleanup_vfile { - os.rm(vfile) or { panic(err) } + os.rm(vfile) or { panic(err.msg) } } } return errors, oks diff --git a/cmd/tools/vcreate.v b/cmd/tools/vcreate.v index 6d17249a48..39cc227360 100644 --- a/cmd/tools/vcreate.v +++ b/cmd/tools/vcreate.v @@ -55,10 +55,10 @@ fn gen_gitignore(name string) string { fn (c &Create) write_vmod(new bool) { vmod_path := if new { '$c.name/v.mod' } else { 'v.mod' } mut vmod := os.create(vmod_path) or { - cerror(err) + cerror(err.msg) 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() } @@ -68,10 +68,10 @@ fn (c &Create) write_main(new bool) { } main_path := if new { '$c.name/${c.name}.v' } else { '${c.name}.v' } mut mainfile := os.create(main_path) or { - cerror(err) + cerror(err.msg) exit(2) } - mainfile.write_str(main_content()) or { panic(err) } + mainfile.write_str(main_content()) or { panic(err.msg) } 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 return } - fl.write_str(gen_gitignore(c.name)) or { panic(err) } + fl.write_str(gen_gitignore(c.name)) or { panic(err.msg) } fl.close() } } @@ -110,7 +110,7 @@ fn create() { } c.description = os.input('Input your project description: ') println('Initialising ...') - os.mkdir(c.name) or { panic(err) } + os.mkdir(c.name) or { panic(err.msg) } c.write_vmod(true) c.write_main(true) c.create_git_repo(c.name) diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 0da4da7509..aa554d2a8b 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -126,7 +126,7 @@ fn (vd VDoc) render_search_index(out Output) { js_search_index.writeln('];') js_search_data.writeln('];') 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) { @@ -162,7 +162,7 @@ fn (vd VDoc) get_resource(name string, out Output) string { output_path := os.join_path(out.path, name) if !os.exists(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 } diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index fce9a448c9..edf1d3a8aa 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -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) output_path := os.join_path(pdoc.out.path, file_name) 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() } @@ -350,15 +350,15 @@ fn (mut vd VDoc) generate_docs_from_file() { out.path = os.real_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 { out.path = os.join_path(out.path, '_docs') if !os.exists(out.path) { - os.mkdir(out.path) or { panic(err) } + os.mkdir(out.path) or { panic(err.msg) } } else { 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) // move favicons to target directory println('Copying favicons...') - favicons := os.ls(favicons_path) or { panic(err) } + favicons := os.ls(favicons_path) or { panic(err.msg) } for favicon in favicons { favicon_path := os.join_path(favicons_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) } } } } diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index 47f010b225..6fa0ef7118 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -175,7 +175,7 @@ fn (foptions &FormatOptions) format_file(file string) { file_name := os.file_name(file) ulid := rand.ulid() 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 { 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 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') } else { 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)) // a .v project has many 'module main' files in one folder // 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{} for f in all_files_in_pfolder { 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`. mut main_fns := 0 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 { if line.contains('fn main()') { main_fns++ diff --git a/cmd/tools/vpm.v b/cmd/tools/vpm.v index f196e52d5d..864f4a069b 100644 --- a/cmd/tools/vpm.v +++ b/cmd/tools/vpm.v @@ -71,7 +71,7 @@ fn main() { 'install' { if module_names.len == 0 && os.exists('./v.mod') { 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 } 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 } println('Removing module "$name"...') 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 author := name.split('.')[0] author_dir := os.real_path(os.join_path(settings.vmodules_path, author)) if os.is_dir_empty(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() { if !os.is_dir(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 { 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 { println('Failed to search vpm.vlang.io. Status code: $r.status_code') exit(1) diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 3bc4407354..9f38d0a72b 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -184,7 +184,7 @@ fn run_repl(workdir string, vrepl_prefix string) { } if r.line.starts_with('print') { 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 } print_output(s) } 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' } - 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 } if !func_call && s.exit_code == 0 && !temp_flag { for r.temp_lines.len > 0 { @@ -355,8 +355,8 @@ fn repl_run_vfile(file string) ?os.Result { eprintln('>> repl_run_vfile file: $file') } s := os.exec('"$vexe" -repl run "$file"') or { - rerror(err) - return error(err) + rerror(err.msg) + return err } return s } diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index 9bf7269332..0ba5c9fa8e 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -27,12 +27,12 @@ fn main() { // The user just wants an independent copy of v, and so we are done. return } - backup_old_version_and_rename_newer() or { panic(err) } + backup_old_version_and_rename_newer() or { panic(err.msg) } println('V built successfully!') } 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 { eprintln('cannot compile to `$vroot`: \n$result.output') exit(1) @@ -76,7 +76,7 @@ fn backup_old_version_and_rename_newer() ?bool { os.rm(v_file) or { } 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:', '') diff --git a/cmd/tools/vsetup-freetype.v b/cmd/tools/vsetup-freetype.v index 0d4b33f14e..b640f12167 100644 --- a/cmd/tools/vsetup-freetype.v +++ b/cmd/tools/vsetup-freetype.v @@ -12,7 +12,7 @@ fn main() { println('Thirdparty "freetype" is already installed.') } else { 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('Thirdparty "freetype" installed successfully.') diff --git a/cmd/tools/vsymlink.v b/cmd/tools/vsymlink.v index 944fbda890..a0f99587bb 100644 --- a/cmd/tools/vsymlink.v +++ b/cmd/tools/vsymlink.v @@ -27,11 +27,11 @@ fn setup_symlink_unix(vexe string) { if os.system("uname -o | grep -q '[A/a]ndroid'") == 1 { link_dir := '/usr/local/bin' 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' } - 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 { println('Symlink "$link_path" has been created') } else { @@ -49,14 +49,14 @@ fn setup_symlink_windows(vexe string) { mut vsymlink := os.join_path(vsymlinkdir, 'v.exe') // Remove old symlink first (v could have been moved, symlink rerun) if !os.exists(vsymlinkdir) { - os.mkdir(vsymlinkdir) or { panic(err) } + os.mkdir(vsymlinkdir) or { panic(err.msg) } } else { if os.exists(vsymlink) { - os.rm(vsymlink) or { panic(err) } + os.rm(vsymlink) or { panic(err.msg) } } else { vsymlink = os.join_path(vsymlinkdir, 'v.bat') if os.exists(vsymlink) { - os.rm(vsymlink) or { panic(err) } + os.rm(vsymlink) or { panic(err.msg) } } vsymlink = os.join_path(vsymlinkdir, 'v.exe') } @@ -69,9 +69,9 @@ fn setup_symlink_windows(vexe string) { eprintln('Creating a batch file instead...') vsymlink = os.join_path(vsymlinkdir, 'v.bat') 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.') } if !os.exists(vsymlink) { @@ -80,7 +80,7 @@ fn setup_symlink_windows(vexe string) { println('Symlink $vsymlink to $vexe created.') println('Checking system %PATH%...') reg_sys_env_handle := get_reg_sys_env_handle() or { - warn_and_exit(err) + warn_and_exit(err.msg) return } // TODO: Fix defers inside ifs @@ -107,7 +107,7 @@ fn setup_symlink_windows(vexe string) { println('Adding symlink directory to system %PATH%...') set_reg_value(reg_sys_env_handle, 'Path', new_sys_env_path) or { C.RegCloseKey(reg_sys_env_handle) - warn_and_exit(err) + warn_and_exit(err.msg) } println('Done.') } diff --git a/cmd/tools/vtest-parser.v b/cmd/tools/vtest-parser.v index b3d56e9b77..d3a21671cb 100644 --- a/cmd/tools/vtest-parser.v +++ b/cmd/tools/vtest-parser.v @@ -124,7 +124,7 @@ fn process_cli_args() &Context { exit(0) } context.all_paths = fp.finalize() or { - context.error(err) + context.error(err.msg) exit(1) } 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" ' context.log(cmd) res := os.exec(cmd) or { os.Result{ - output: err + output: err.msg exit_code: ecode_exec } } context.log('worker exit_code: $res.exit_code | worker output:\n$res.output') diff --git a/cmd/tools/vup.v b/cmd/tools/vup.v index 7ff83b8f69..bd45d6e77e 100644 --- a/cmd/tools/vup.v +++ b/cmd/tools/vup.v @@ -41,7 +41,7 @@ fn main() { app.backup('cmd/tools/vup.exe') } 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() } @@ -88,7 +88,7 @@ fn (app App) make(vself string) { $if windows { 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) } @@ -121,7 +121,7 @@ fn (app App) git_command(command string) { git_result := os.exec('git $command') or { app.get_git() // 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 { 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 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') - panic(err) + panic(err.msg) } os.exec('$os.getwd()/git32.exe') or { 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. eprintln("error: Install `git` using your system's package manager") diff --git a/cmd/tools/vvet/vet_test.v b/cmd/tools/vvet/vet_test.v index 6209f9168c..fa7fa538d4 100644 --- a/cmd/tools/vvet/vet_test.v +++ b/cmd/tools/vvet/vet_test.v @@ -21,7 +21,7 @@ fn test_vet() { } 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')) tests.sort() return tests @@ -34,8 +34,8 @@ fn check_path(vexe string, dir string, tests []string) int { program := path print(path + ' ') // -force is needed so that `v vet` would not skip the regression files - res := os.exec('$vexe vet -force $program') or { panic(err) } - mut expected := os.read_file(program.replace('.vv', '') + '.out') 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.msg) } expected = clean_line_endings(expected) found := clean_line_endings(res.output) if expected != found { diff --git a/doc/docs.md b/doc/docs.md index 68a552ee37..5f5eaf7221 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1321,7 +1321,7 @@ import os fn read_log() { mut ok := false - mut f := os.open('log.txt') or { panic(err) } + mut f := os.open('log.txt') or { panic(err.msg) } defer { f.close() } @@ -2401,7 +2401,7 @@ any further. The body of `f` is essentially a condensed version of: ```v ignore - resp := http.get(url) or { return error(err) } + resp := http.get(url) or { return err } 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. 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. @@ -3495,7 +3495,7 @@ Full list of builtin options: module main fn main() { 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.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: ```v ignore 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') ``` diff --git a/examples/database/orm.v b/examples/database/orm.v index 854a904cfe..4e3303060e 100644 --- a/examples/database/orm.v +++ b/examples/database/orm.v @@ -16,7 +16,7 @@ struct User { } 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("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);") diff --git a/examples/database/pg/customer.v b/examples/database/pg/customer.v index d159b83c6b..2dac25ddb9 100644 --- a/examples/database/pg/customer.v +++ b/examples/database/pg/customer.v @@ -41,7 +41,7 @@ fn main() { // by adding `limit 1` we tell V that there will be only one object println(dash) - existing := db.select from Customer where id == 1 limit 1 or { panic(err) } + existing := db.select from Customer where id == 1 limit 1 or { panic(err.msg) } println('Existing customer name: $existing.name') println('Existing customer full information:') println(existing) diff --git a/examples/flappylearning/game.v b/examples/flappylearning/game.v index 5b1ef094dc..7c045607c9 100644 --- a/examples/flappylearning/game.v +++ b/examples/flappylearning/game.v @@ -212,13 +212,13 @@ fn (mut app App) run() { fn init_images(mut app App) { $if android { - background := os.read_apk_asset('img/background.png') or { panic(err) } + background := os.read_apk_asset('img/background.png') or { panic(err.msg) } 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) - 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) - 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) } $else { app.background = app.gg.create_image(os.resource_abs_path('assets/img/background.png')) diff --git a/examples/path_tracing.v b/examples/path_tracing.v index 2c32ae96bc..dbc6ea66dc 100644 --- a/examples/path_tracing.v +++ b/examples/path_tracing.v @@ -98,15 +98,15 @@ fn new_image(w int, h int) Image { // write out a .ppm file fn (image Image) save_as_ppm(file_name string) { npixels := image.width * image.height - mut f_out := os.create(file_name) or { panic(err) } - f_out.writeln('P3') or { panic(err) } - f_out.writeln('$image.width $image.height') or { panic(err) } - f_out.writeln('255') or { panic(err) } + mut f_out := os.create(file_name) or { panic(err.msg) } + f_out.writeln('P3') or { panic(err.msg) } + f_out.writeln('$image.width $image.height') or { panic(err.msg) } + f_out.writeln('255') or { panic(err.msg) } for i in 0 .. npixels { c_r := to_int(unsafe { image.data[i] }.x) c_g := to_int(unsafe { image.data[i] }.y) c_b := to_int(unsafe { image.data[i] }.z) - f_out.write_str('$c_r $c_g $c_b ') or { panic(err) } + f_out.write_str('$c_r $c_g $c_b ') or { panic(err.msg) } } f_out.close() } diff --git a/examples/process/command.v b/examples/process/command.v index 718ce96326..d6cf12cb20 100644 --- a/examples/process/command.v +++ b/examples/process/command.v @@ -10,7 +10,7 @@ fn exec(path string) string { mut cmd := os.Command{ path: path } - cmd.start() or { panic(err) } + cmd.start() or { panic(err.msg) } for { line = cmd.read_line() diff --git a/examples/process/execve.v b/examples/process/execve.v index f840c8dcd3..f8b611a7a9 100644 --- a/examples/process/execve.v +++ b/examples/process/execve.v @@ -5,7 +5,7 @@ import os fn exec(args []string) { os.execve('/bin/bash', args, []) or { // eprintln(err) - panic(err) + panic(err.msg) } } diff --git a/examples/process/process_script.v b/examples/process/process_script.v index fa415e7839..48d27abff2 100644 --- a/examples/process/process_script.v +++ b/examples/process/process_script.v @@ -47,7 +47,7 @@ echo redirect 1 to 2 1>&2 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 // this will work because stderr/stdout are smaller than 4096 chars, once larger there can be deadlocks diff --git a/examples/regex/regex_example.v b/examples/regex/regex_example.v index b202bf7fc2..00f7f3042b 100644 --- a/examples/regex/regex_example.v +++ b/examples/regex/regex_example.v @@ -20,12 +20,12 @@ fn convert_html_rgb(in_col string) u32 { 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 - // 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. *** 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) println('start: $start, end: $end') mut res := u32(0) @@ -49,7 +49,7 @@ fn convert_html_rgb_n(in_col string) u32 { query := '#(?P[a-fA-F0-9]{$n_digit})(?P[a-fA-F0-9]{$n_digit})(?P[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) println('start: $start, end: $end') mut res := u32(0) diff --git a/examples/templates/templates.v b/examples/templates/templates.v index a4917227af..dbcea78303 100644 --- a/examples/templates/templates.v +++ b/examples/templates/templates.v @@ -171,12 +171,12 @@ fn data_get() []SiteConfig { fn data_dump(data []SiteConfig) { a := json.encode_pretty(data) - os.write_file(os.resource_abs_path('data.json'), a) or { panic(err) } + os.write_file(os.resource_abs_path('data.json'), a) or { panic(err.msg) } } fn data_load() []SiteConfig { - data := os.read_file(os.resource_abs_path('data.json')) or { panic(err) } - a := json.decode([]SiteConfig, data) 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.msg) } return a } @@ -192,5 +192,5 @@ fn main() { // data_dump(data) b := filled_in_template() println(b) - os.write_file('result.md', b) or { panic(err) } + os.write_file('result.md', b) or { panic(err.msg) } } diff --git a/examples/term.ui/text_editor.v b/examples/term.ui/text_editor.v index a08efa59be..7431fbccfe 100644 --- a/examples/term.ui/text_editor.v +++ b/examples/term.ui/text_editor.v @@ -44,7 +44,7 @@ fn (mut a App) set_status(msg string, duration_ms int) { fn (mut a App) save() { if a.cfile().len > 0 { b := a.ed - os.write_file(a.cfile(), b.raw()) or { panic(err) } + os.write_file(a.cfile(), b.raw()) or { panic(err.msg) } a.set_status('Saved', 2000) } else { a.set_status('No file loaded', 4000) @@ -456,7 +456,7 @@ fn (mut a App) init_file() { // 'vico: ' + a.tui.set_window_title(a.files[a.current_file]) mut b := a.ed - content := os.read_file(a.files[a.current_file]) or { panic(err) } + content := os.read_file(a.files[a.current_file]) or { panic(err.msg) } b.put(content) a.ed.cursor.pos_x = init_x a.ed.cursor.pos_y = init_y diff --git a/examples/ttf_font/example_ttf.v b/examples/ttf_font/example_ttf.v index 85eb26b00a..16c2493f55 100644 --- a/examples/ttf_font/example_ttf.v +++ b/examples/ttf_font/example_ttf.v @@ -135,7 +135,7 @@ fn main() { // load TTF fonts for font_path in font_paths { mut tf := ttf.TTF_File{} - tf.buf = os.read_bytes(font_path) or { panic(err) } + tf.buf = os.read_bytes(font_path) or { panic(err.msg) } println('TrueTypeFont file [$font_path] len: $tf.buf.len') tf.init() println('Unit per EM: $tf.units_per_em') diff --git a/examples/v_script.vsh b/examples/v_script.vsh index 360435d200..ad0dd5b701 100755 --- a/examples/v_script.vsh +++ b/examples/v_script.vsh @@ -12,14 +12,14 @@ mkdir('v_script_dir') println("\nEntering into v_script_dir and listing it's files.") chdir('v_script_dir') -files := ls('.') or { panic(err) } +files := ls('.') or { panic(err.msg) } println(files) println('\nCreating foo.txt') create('foo.txt')? println('\nFiles:') -again_ls := ls('.') or { panic(err) } +again_ls := ls('.') or { panic(err.msg) } println(again_ls) println('\nRemoving foo.txt and v_script_dir') diff --git a/examples/websocket/client-server/server.v b/examples/websocket/client-server/server.v index 154d2d44e5..e2cc352e45 100644 --- a/examples/websocket/client-server/server.v +++ b/examples/websocket/client-server/server.v @@ -28,7 +28,7 @@ fn start_server() ? { for i, _ in m.clients { mut c := m.clients[i] if c.client.state == .open && c.client.id != ws.id { - c.client.write(msg.payload, websocket.OPCode.text_frame) or { panic(err) } + c.client.write(msg.payload, websocket.OPCode.text_frame) or { panic(err.msg) } } } }, s) diff --git a/examples/websocket/ping.v b/examples/websocket/ping.v index a68fa73c51..88aabb63b1 100644 --- a/examples/websocket/ping.v +++ b/examples/websocket/ping.v @@ -25,7 +25,7 @@ fn start_server() ? { return true }) ? s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? { - ws.write(msg.payload, msg.opcode) or { panic(err) } + ws.write(msg.payload, msg.opcode) or { panic(err.msg) } }) s.on_close(fn (mut ws websocket.Client, code int, reason string) ? { // println('client ($ws.id) closed connection') diff --git a/tutorials/code/blog/blog.v b/tutorials/code/blog/blog.v index c17a34de16..1889432a1d 100644 --- a/tutorials/code/blog/blog.v +++ b/tutorials/code/blog/blog.v @@ -32,7 +32,7 @@ pub fn (app &App) index() vweb.Result { } 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 ''," + "text text default ''" + ');') } diff --git a/vlib/builtin/bare/syscallwrapper_test.v b/vlib/builtin/bare/syscallwrapper_test.v index b293978c8e..63022c90a1 100644 --- a/vlib/builtin/bare/syscallwrapper_test.v +++ b/vlib/builtin/bare/syscallwrapper_test.v @@ -13,7 +13,7 @@ fn test_syscallwrappers() { os.chdir(dot_checks) checks_v := "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("failed") assert rc.exit_code == 0 diff --git a/vlib/builtin/js/builtin.v b/vlib/builtin/js/builtin.v index d10bbd24d0..cd2bbcb783 100644 --- a/vlib/builtin/js/builtin.v +++ b/vlib/builtin/js/builtin.v @@ -44,8 +44,8 @@ pub fn exit(c int) { pub fn unwrap(opt any) any { o := &Option(opt) - if o.not_ok { - js_throw(o.error) + if o.state != 0 { + js_throw(o.err) } return opt } @@ -55,38 +55,44 @@ pub fn panic(s string) { exit(1) } +struct Option { + state byte + err Error + data T +} -struct Option { - not_ok bool - is_none bool - error string - ecode int - data any +pub struct Error { +pub: + msg string + code int } pub fn (o Option) str() string { - if !o.not_ok { + if o.state == 0 { return 'Option{ ok }' } - if o.is_none { + if o.state == 1 { return 'Option{ none }' } - return 'Option{ error: "${o.error}" }' + return 'Option{ error: "${o.err}" }' } pub fn error(s string) Option { return Option{ - not_ok: true - is_none: false - error: s + state: 2 + err: { + msg: s + } } } pub fn error_with_code(s string, code int) Option { return Option{ - not_ok: true - is_none: false - error: s - ecode: code + state: 2 + err: { + msg: s + code: code + } } + } diff --git a/vlib/cli/command.v b/vlib/cli/command.v index 6a66490b10..ca917a50f0 100644 --- a/vlib/cli/command.v +++ b/vlib/cli/command.v @@ -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 if version_flag { 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) } } @@ -280,7 +280,7 @@ fn (cmd Command) check_required_flags() { pub fn (cmd Command) execute_help() { if cmd.commands.contains('help') { 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 { print(cmd.help_message()) } diff --git a/vlib/cli/command_test.v b/vlib/cli/command_test.v index aae7199c85..8e96802fb3 100644 --- a/vlib/cli/command_test.v +++ b/vlib/cli/command_test.v @@ -135,7 +135,7 @@ fn test_if_required_flags_get_set() { } 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' } diff --git a/vlib/cli/flag_test.v b/vlib/cli/flag_test.v index 7fb9a3f686..2fe533d837 100644 --- a/vlib/cli/flag_test.v +++ b/vlib/cli/flag_test.v @@ -5,16 +5,16 @@ fn test_if_string_flag_parses() { flag: .string name: 'flag' } - flag.parse(['-flag', 'value1'], false) or { panic(err) } - mut value := flag.get_string() or { panic(err) } + flag.parse(['-flag', 'value1'], false) or { panic(err.msg) } + mut value := flag.get_string() or { panic(err.msg) } assert value == 'value1' flag = cli.Flag{ flag: .string name: 'flag' } - flag.parse(['-flag=value2'], false) or { panic(err) } - value = flag.get_string() or { panic(err) } + flag.parse(['-flag=value2'], false) or { panic(err.msg) } + value = flag.get_string() or { panic(err.msg) } assert value == 'value2' flag = cli.Flag{ @@ -22,9 +22,9 @@ fn test_if_string_flag_parses() { name: 'flag' multiple: true } - flag.parse(['-flag=value1'], false) or { panic(err) } - flag.parse(['-flag=value2'], false) or { panic(err) } - mut values := flag.get_strings() or { panic(err) } + flag.parse(['-flag=value1'], false) or { panic(err.msg) } + flag.parse(['-flag=value2'], false) or { panic(err.msg) } + mut values := flag.get_strings() or { panic(err.msg) } assert values == ['value1', 'value2'] 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'] } @@ -50,20 +50,20 @@ fn test_if_bool_flag_parses() { name: 'flag' } mut value := false - flag.parse(['-flag'], false) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['-flag'], false) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == true - flag.parse(['-flag', 'false'], false) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['-flag', 'false'], false) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == false - flag.parse(['-flag', 'true'], false) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['-flag', 'true'], false) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == true - flag.parse(['-flag=false'], false) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['-flag=false'], false) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == false - flag.parse(['-flag=true'], false) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['-flag=true'], false) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == true } @@ -74,8 +74,8 @@ fn test_if_int_flag_parses() { } mut value := 0 - flag.parse(['-flag', '42'], false) or { panic(err) } - value = flag.get_int() or { panic(err) } + flag.parse(['-flag', '42'], false) or { panic(err.msg) } + value = flag.get_int() or { panic(err.msg) } assert value == 42 flag = cli.Flag{ @@ -83,8 +83,8 @@ fn test_if_int_flag_parses() { name: 'flag' } - flag.parse(['-flag=45'], false) or { panic(err) } - value = flag.get_int() or { panic(err) } + flag.parse(['-flag=45'], false) or { panic(err.msg) } + value = flag.get_int() or { panic(err.msg) } assert value == 45 flag = cli.Flag{ @@ -93,9 +93,9 @@ fn test_if_int_flag_parses() { multiple: true } - flag.parse(['-flag=42'], false) or { panic(err) } - flag.parse(['-flag=45'], false) or { panic(err) } - mut values := flag.get_ints() or { panic(err) } + flag.parse(['-flag=42'], false) or { panic(err.msg) } + flag.parse(['-flag=45'], false) or { panic(err.msg) } + mut values := flag.get_ints() or { panic(err.msg) } assert values == [42, 45] 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] } @@ -121,8 +121,8 @@ fn test_if_float_flag_parses() { name: 'flag' } mut value := f64(0) - flag.parse(['-flag', '3.14158'], false) or { panic(err) } - value = flag.get_float() or { panic(err) } + flag.parse(['-flag', '3.14158'], false) or { panic(err.msg) } + value = flag.get_float() or { panic(err.msg) } assert value == 3.14158 flag = cli.Flag{ @@ -130,9 +130,9 @@ fn test_if_float_flag_parses() { 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 - value = flag.get_float() or { panic(err) } + value = flag.get_float() or { panic(err.msg) } assert value == 3.14159 flag = cli.Flag{ @@ -141,9 +141,9 @@ fn test_if_float_flag_parses() { multiple: true } - flag.parse(['-flag=3.1'], false) or { panic(err) } - flag.parse(['-flag=1.3'], false) or { panic(err) } - mut values := flag.get_floats() or { panic(err) } + flag.parse(['-flag=3.1'], false) or { panic(err.msg) } + flag.parse(['-flag=1.3'], false) or { panic(err.msg) } + mut values := flag.get_floats() or { panic(err.msg) } assert values == [3.1, 1.3] 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] } @@ -170,8 +170,8 @@ fn test_if_flag_parses_with_abbrev() { abbrev: 'f' } mut value := false - flag.parse(['--flag'], true) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['--flag'], true) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == true value = false @@ -180,8 +180,8 @@ fn test_if_flag_parses_with_abbrev() { name: 'flag' abbrev: 'f' } - flag.parse(['-f'], true) or { panic(err) } - value = flag.get_bool() or { panic(err) } + flag.parse(['-f'], true) or { panic(err.msg) } + value = flag.get_bool() or { panic(err.msg) } assert value == true } @@ -191,7 +191,7 @@ fn test_if_multiple_value_on_single_value() { 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) { panic("No multiple value flag don't raise an error!") diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index 2d56d5513f..923e4f169f 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -110,7 +110,7 @@ pub fn (mut d Digest) checksum() []byte { tmp[0] = 0x80 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 - 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 // blocks (i.e. a multiple of 64 bytes) have been hashed. if d.nx != 0 { @@ -127,7 +127,7 @@ pub fn (mut d Digest) checksum() []byte { // sum returns the MD5 checksum of the data. pub fn sum(data []byte) []byte { mut d := new() - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } return d.checksum() } diff --git a/vlib/crypto/sha1/sha1.v b/vlib/crypto/sha1/sha1.v index 2e4b6fe66f..eb3fb633a8 100644 --- a/vlib/crypto/sha1/sha1.v +++ b/vlib/crypto/sha1/sha1.v @@ -109,14 +109,14 @@ fn (mut d Digest) checksum() []byte { mut tmp := []byte{len: (64)} tmp[0] = 0x80 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 { - 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. len <<= 3 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)} binary.big_endian_put_u32(mut digest, d.h[0]) 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`. pub fn sum(data []byte) []byte { mut d := new() - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } return d.checksum() } diff --git a/vlib/crypto/sha256/sha256.v b/vlib/crypto/sha256/sha256.v index af37727c7d..95795d58de 100644 --- a/vlib/crypto/sha256/sha256.v +++ b/vlib/crypto/sha256/sha256.v @@ -147,14 +147,14 @@ fn (mut d Digest) checksum() []byte { mut tmp := []byte{len: (64)} tmp[0] = 0x80 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 { - 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. len <<= u64(3) 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 { panic('d.nx != 0') } @@ -181,14 +181,14 @@ pub fn sum(data []byte) []byte { // sum256 returns the SHA256 checksum of the data. pub fn sum256(data []byte) []byte { mut d := new() - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } return d.checksum() } // sum224 returns the SHA224 checksum of the data. pub fn sum224(data []byte) []byte { mut d := new224() - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } sum := d.checksum() sum224 := []byte{len: (size224)} copy(sum224, sum[..size224]) diff --git a/vlib/crypto/sha512/sha512.v b/vlib/crypto/sha512/sha512.v index 0ddff114e1..7f972243cb 100644 --- a/vlib/crypto/sha512/sha512.v +++ b/vlib/crypto/sha512/sha512.v @@ -219,15 +219,15 @@ fn (mut d Digest) checksum() []byte { mut tmp := []byte{len: (128)} tmp[0] = 0x80 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 { - 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. 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[8..], len) - d.write(tmp[..16]) or { panic(err) } + d.write(tmp[..16]) or { panic(err.msg) } if 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. pub fn sum512(data []byte) []byte { mut d := new_digest(.sha512) - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } return d.checksum() } // sum384 returns the SHA384 checksum of the data. pub fn sum384(data []byte) []byte { mut d := new_digest(.sha384) - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } sum := d.checksum() sum384 := []byte{len: (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. pub fn sum512_224(data []byte) []byte { mut d := new_digest(.sha512_224) - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } sum := d.checksum() sum224 := []byte{len: (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. pub fn sum512_256(data []byte) []byte { mut d := new_digest(.sha512_256) - d.write(data) or { panic(err) } + d.write(data) or { panic(err.msg) } sum := d.checksum() sum256 := []byte{len: (size256)} copy(sum256, sum[..size256]) diff --git a/vlib/dl/example/use_test.v b/vlib/dl/example/use_test.v index 812281d8a2..9bb7396fe2 100644 --- a/vlib/dl/example/use_test.v +++ b/vlib/dl/example/use_test.v @@ -40,7 +40,7 @@ fn test_can_compile_main_program() { fn v_compile(vopts string) os.Result { cmd := '"$vexe" -showcc $vopts' 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') // assert res.exit_code == 0 $if !windows { diff --git a/vlib/encoding/csv/reader.v b/vlib/encoding/csv/reader.v index 90abd036ca..2d9de9132d 100644 --- a/vlib/encoding/csv/reader.v +++ b/vlib/encoding/csv/reader.v @@ -46,10 +46,10 @@ pub fn (mut r Reader) read() ?[]string { // mut records := []string{} // for { // record := r.read_record() or { -// if error(err).error == err_eof.error { +// if err.error == err_eof.error { // return records // } else { -// return error(err) +// return err // } // } // records << record diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index 59d90af7d3..45ca1e9b2b 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -162,7 +162,7 @@ fn gg_init_sokol_window(user_data voidptr) { font_path: g.config.font_path custom_bold_font_path: g.config.custom_bold_font_path scale: dpi_scale() - ) or { panic(err) } + ) or { panic(err.msg) } // println('FT took ${time.ticks()-t} ms') g.font_inited = true } else { @@ -174,7 +174,7 @@ fn gg_init_sokol_window(user_data voidptr) { bytes_mono: g.config.font_bytes_mono bytes_italic: g.config.font_bytes_italic scale: sapp.dpi_scale() - ) or { panic(err) } + ) or { panic(err.msg) } g.font_inited = true } else { sfont := system_font_path() @@ -183,7 +183,7 @@ fn gg_init_sokol_window(user_data voidptr) { font_path: sfont custom_bold_font_path: g.config.custom_bold_font_path scale: sapp.dpi_scale() - ) or { panic(err) } + ) or { panic(err.msg) } g.font_inited = true } } diff --git a/vlib/io/os_file_reader_test.v b/vlib/io/os_file_reader_test.v index 39606c8a03..c59465f8ff 100644 --- a/vlib/io/os_file_reader_test.v +++ b/vlib/io/os_file_reader_test.v @@ -3,7 +3,7 @@ import io fn read_file(file string, cap int) []string { mut lines := []string{} - mut f := os.open(file) or { panic(err) } + mut f := os.open(file) or { panic(err.msg) } defer { f.close() } diff --git a/vlib/io/util/util_test.v b/vlib/io/util/util_test.v index ff09e7e5dd..64686efe52 100644 --- a/vlib/io/util/util_test.v +++ b/vlib/io/util/util_test.v @@ -12,7 +12,7 @@ fn testsuite_begin() { eprintln('testsuite_begin, tfolder = $tfolder') os.rmdir_all(tfolder) or { } assert !os.is_dir(tfolder) - os.mkdir_all(tfolder) or { panic(err) } + os.mkdir_all(tfolder) or { panic(err.msg) } os.chdir(tfolder) assert os.is_dir(tfolder) } diff --git a/vlib/json/json_test.v b/vlib/json/json_test.v index 428b50455e..0b1a0ca2ff 100644 --- a/vlib/json/json_test.v +++ b/vlib/json/json_test.v @@ -370,7 +370,7 @@ struct Info { } 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.items' == '[]' assert '$info.maps' == '{}' diff --git a/vlib/log/log.v b/vlib/log/log.v index 4ba9e5e45e..a5ce5f7290 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -106,7 +106,7 @@ pub fn (mut l Log) close() { fn (mut l Log) log_file(s string, level Level) { timestamp := time.now().format_ss() 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. diff --git a/vlib/net/ftp/ftp.v b/vlib/net/ftp/ftp.v index f27ebb537a..8fab97a5f5 100644 --- a/vlib/net/ftp/ftp.v +++ b/vlib/net/ftp/ftp.v @@ -56,7 +56,7 @@ fn (mut dtp DTP) read() ?[]byte { } fn (mut dtp DTP) close() { - dtp.conn.close() or { panic(err) } + dtp.conn.close() or { panic(err.msg) } } struct FTP { diff --git a/vlib/net/ftp/ftp_test.v b/vlib/net/ftp/ftp_test.v index a62316d00c..a98ff88975 100644 --- a/vlib/net/ftp/ftp_test.v +++ b/vlib/net/ftp/ftp_test.v @@ -8,14 +8,14 @@ fn test_ftp_cleint() { // that is why it is not a very good idea to run it in CI. // If you want to run it manually, use: // `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() ? { mut zftp := ftp.new() // eprintln(zftp) defer { - zftp.close() or { panic(err) } + zftp.close() or { panic(err.msg) } } connect_result := zftp.connect('ftp.redhat.com') ? assert connect_result diff --git a/vlib/net/html/dom.v b/vlib/net/html/dom.v index f56e9c2dc3..25921c38b4 100644 --- a/vlib/net/html/dom.v +++ b/vlib/net/html/dom.v @@ -25,7 +25,7 @@ mut: fn (mut dom DocumentObjectModel) print_debug(data string) { $if debug { if data.len > 0 { - dom.debug_file.writeln(data) or { panic(err) } + dom.debug_file.writeln(data) or { panic(err.msg) } } } } diff --git a/vlib/net/html/parser.v b/vlib/net/html/parser.v index ac6e97e5d4..a26826c8b2 100644 --- a/vlib/net/html/parser.v +++ b/vlib/net/html/parser.v @@ -53,7 +53,7 @@ fn (parser Parser) builder_str() string { fn (mut parser Parser) print_debug(data string) { $if debug { if data.len > 0 { - parser.debug_file.writeln(data) or { panic(err) } + parser.debug_file.writeln(data) or { panic(err.msg) } } } } diff --git a/vlib/net/http/download.v b/vlib/net/http/download.v index 036e611c69..51c216cab5 100644 --- a/vlib/net/http/download.v +++ b/vlib/net/http/download.v @@ -9,7 +9,7 @@ pub fn download_file(url string, out string) ? { $if debug_http ? { 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) ? // download_file_with_progress(url, out, empty, empty) } diff --git a/vlib/net/http/http_httpbin_test.v b/vlib/net/http/http_httpbin_test.v index cbdfcd009d..38520043b7 100644 --- a/vlib/net/http/http_httpbin_test.v +++ b/vlib/net/http/http_httpbin_test.v @@ -34,7 +34,7 @@ fn http_fetch_mock(_methods []string, _config FetchConfig) ?[]Response { fn test_http_fetch_bare() { $if !network ? { return } responses := http_fetch_mock([], FetchConfig{}) or { - panic(err) + panic(err.msg) } for response in responses { assert response.status_code == 200 @@ -46,11 +46,11 @@ fn test_http_fetch_with_data() { responses := http_fetch_mock(['POST', 'PUT', 'PATCH', 'DELETE'], { data: 'hello world' }) or { - panic(err) + panic(err.msg) } for response in responses { payload := json.decode(HttpbinResponseBody,response.text) or { - panic(err) + panic(err.msg) } assert payload.data == 'hello world' } @@ -64,11 +64,11 @@ fn test_http_fetch_with_params() { 'c': 'd' } }) or { - panic(err) + panic(err.msg) } for response in responses { // payload := json.decode(HttpbinResponseBody,response.text) or { - // panic(err) + // panic(err.msg) // } assert response.status_code == 200 // TODO @@ -84,11 +84,11 @@ fn test_http_fetch_with_headers() { 'Test-Header': 'hello world' } }) or { - panic(err) + panic(err.msg) } for response in responses { // payload := json.decode(HttpbinResponseBody,response.text) or { - // panic(err) + // panic(err.msg) // } assert response.status_code == 200 // TODO diff --git a/vlib/net/http/http_test.v b/vlib/net/http/http_test.v index adc1c0aab6..0ec8e7eb45 100644 --- a/vlib/net/http/http_test.v +++ b/vlib/net/http/http_test.v @@ -16,7 +16,7 @@ fn test_http_get_from_vlang_utc_now() { for url in urls { println('Test getting current time from $url by http.get') res := http.get(url) or { - panic(err) + panic(err.msg) } assert 200 == res.status_code assert res.text.len > 0 @@ -40,7 +40,7 @@ fn test_public_servers() { for url in urls { println('Testing http.get on public url: $url ') res := http.get(url) or { - panic(err) + panic(err.msg) } assert 200 == res.status_code assert res.text.len > 0 @@ -54,7 +54,7 @@ fn test_relative_redirects() { return } // tempfix periodic: httpbin relative redirects are broken res := http.get('https://httpbin.org/relative-redirect/3?abc=xyz') or { - panic(err) + panic(err.msg) } assert 200 == res.status_code assert res.text.len > 0 diff --git a/vlib/net/tcp_simple_client_server_test.v b/vlib/net/tcp_simple_client_server_test.v index dffe45edf3..6e95cdc216 100644 --- a/vlib/net/tcp_simple_client_server_test.v +++ b/vlib/net/tcp_simple_client_server_test.v @@ -7,9 +7,9 @@ const ( ) fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) { - mut server := net.listen_tcp(server_port) or { panic(err) } - mut client := net.dial_tcp('127.0.0.1:$server_port') or { panic(err) } - mut socket := server.accept() 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.msg) } + mut socket := server.accept() or { panic(err.msg) } $if debug_peer_ip ? { ip := con.peer_ip() or { '$err' } eprintln('connection peer_ip: $ip') diff --git a/vlib/net/tcp_test.v b/vlib/net/tcp_test.v index 557300c73d..5a0988d389 100644 --- a/vlib/net/tcp_test.v +++ b/vlib/net/tcp_test.v @@ -44,8 +44,8 @@ fn echo() ? { } 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) - echo() or { panic(err) } + echo() or { panic(err.msg) } l.close() or { } } diff --git a/vlib/net/unix/unix_test.v b/vlib/net/unix/unix_test.v index 2b5ffce6c6..4177031019 100644 --- a/vlib/net/unix/unix_test.v +++ b/vlib/net/unix/unix_test.v @@ -51,8 +51,8 @@ fn echo() ? { } 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) - echo() or { panic(err) } + echo() or { panic(err.msg) } l.close() or { } } diff --git a/vlib/orm/orm_test.v b/vlib/orm/orm_test.v index e29d4435e1..7a2be7e8ca 100644 --- a/vlib/orm/orm_test.v +++ b/vlib/orm/orm_test.v @@ -22,7 +22,7 @@ struct Foo { } 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("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);") 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')) return } - db := pg.connect(dbname: dbname, user: dbuser) or { panic(err) } + db := pg.connect(dbname: dbname, user: dbuser) or { panic(err.msg) } _ = db nr_modules := db.select count from modules //nr_modules := db.select count from Modules where id == 1 diff --git a/vlib/os/inode_test.v b/vlib/os/inode_test.v index 395756e228..1227037205 100644 --- a/vlib/os/inode_test.v +++ b/vlib/os/inode_test.v @@ -11,14 +11,14 @@ fn testsuite_begin() { eprintln('testsuite_begin, tfolder = $tfolder') os.rmdir_all(tfolder) or { } assert !os.is_dir(tfolder) - os.mkdir_all(tfolder) or { panic(err) } + os.mkdir_all(tfolder) or { panic(err.msg) } os.chdir(tfolder) assert os.is_dir(tfolder) } fn testsuite_end() { 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) } @@ -27,7 +27,7 @@ fn test_inode_file_type() { mut file := os.open_file(filename, 'w', 0o600) or { return } file.close() mode := os.inode(filename) - os.rm(filename) or { panic(err) } + os.rm(filename) or { panic(err.msg) } assert mode.typ == .regular } diff --git a/vlib/os/os.v b/vlib/os/os.v index c3c7341e10..e762c365bc 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -61,8 +61,8 @@ pub fn cp_all(src string, dst string, overwrite bool) ? { } } cp_all(sp, dp, overwrite) or { - rmdir(dp) or { return error(err) } - return error(err) + rmdir(dp) or { return err } + return err } } } @@ -507,7 +507,7 @@ pub fn cache_dir() string { } cdir := join_path(home_dir(), '.cache') if !is_dir(cdir) && !is_link(cdir) { - mkdir(cdir) or { panic(err) } + mkdir(cdir) or { panic(err.msg) } } return cdir } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 141df342a6..1f5e1efaa5 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -15,7 +15,7 @@ fn testsuite_begin() { eprintln('testsuite_begin, tfolder = $tfolder') os.rmdir_all(tfolder) or { } assert !os.is_dir(tfolder) - os.mkdir_all(tfolder) or { panic(err) } + os.mkdir_all(tfolder) or { panic(err.msg) } os.chdir(tfolder) assert os.is_dir(tfolder) // println('args_at_start: $args_at_start') @@ -37,13 +37,13 @@ fn test_open_file() { assert err.msg == 'No such file or directory' os.File{} } - mut file := os.open_file(filename, 'w+', 0o666) or { panic(err) } - file.write_str(hello) or { panic(err) } + mut file := os.open_file(filename, 'w+', 0o666) or { panic(err.msg) } + file.write_str(hello) or { panic(err.msg) } file.close() assert hello.len == os.file_size(filename) read_hello := os.read_file(filename) or { panic('error reading file $filename') } assert hello == read_hello - os.rm(filename) or { panic(err) } + os.rm(filename) or { panic(err.msg) } } fn test_open_file_binary() { @@ -53,14 +53,14 @@ fn test_open_file_binary() { assert err.msg == 'No such file or directory' 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() file.write_bytes(bytes.data, bytes.len) file.close() assert hello.len == os.file_size(filename) read_hello := os.read_bytes(filename) or { panic('error reading file $filename') } assert bytes == read_hello - os.rm(filename) or { panic(err) } + os.rm(filename) or { panic(err.msg) } } // fn test_file_get_line() { @@ -86,24 +86,24 @@ fn test_open_file_binary() { fn test_create_file() { filename := './test1.txt' hello := 'hello world!' - mut f := os.create(filename) or { panic(err) } - f.write_str(hello) or { panic(err) } + mut f := os.create(filename) or { panic(err.msg) } + f.write_str(hello) or { panic(err.msg) } f.close() assert hello.len == os.file_size(filename) - os.rm(filename) or { panic(err) } + os.rm(filename) or { panic(err.msg) } } fn test_is_file() { // Setup 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') // Test things that shouldn't be a file assert os.is_file(work_dir) == false assert os.is_file('non-existent_file.tmp') == false // Test 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) // Test dir symlinks $if windows { @@ -126,11 +126,11 @@ fn test_is_file() { fn test_write_and_read_string_to_file() { filename := './test1.txt' 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) read_hello := os.read_file(filename) or { panic('error reading file $filename') } 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 @@ -166,16 +166,16 @@ fn test_write_and_read_bytes() { assert nread == 0 file_read.close() // 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() { folder := './test1' - os.mkdir(folder) or { panic(err) } + os.mkdir(folder) or { panic(err.msg) } 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 - os.rmdir(folder) or { panic(err) } + os.rmdir(folder) or { panic(err.msg) } folder_exists := os.is_dir(folder) assert folder_exists == false } @@ -189,63 +189,63 @@ fn walk_callback(file string) { fn test_walk() { folder := 'test_walk' - os.mkdir(folder) or { panic(err) } + os.mkdir(folder) or { panic(err.msg) } 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.rm(file1) or { panic(err) } - os.rmdir(folder) or { panic(err) } + os.rm(file1) or { panic(err.msg) } + os.rmdir(folder) or { panic(err.msg) } } fn test_cp() { old_file_name := 'cp_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') } - old_file := os.read_file(old_file_name) or { panic(err) } - new_file := os.read_file(new_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.msg) } assert old_file == new_file - os.rm(old_file_name) or { panic(err) } - os.rm(new_file_name) or { panic(err) } + os.rm(old_file_name) or { panic(err.msg) } + os.rm(new_file_name) or { panic(err.msg) } } fn test_mv() { 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 tfile1 := os.join_path(work_dir, 'file') tfile2 := os.join_path(work_dir, 'file.test') tfile3 := os.join_path(work_dir, 'file.3') tfile_content := 'temporary file' - os.write_file(tfile1, tfile_content) or { panic(err) } - os.write_file(tfile2, tfile_content) or { panic(err) } + os.write_file(tfile1, tfile_content) or { panic(err.msg) } + os.write_file(tfile2, tfile_content) or { panic(err.msg) } // Setup test dirs tdir1 := os.join_path(work_dir, 'dir') tdir2 := os.join_path(work_dir, 'dir2') tdir3 := os.join_path(work_dir, 'dir3') - os.mkdir(tdir1) or { panic(err) } - os.mkdir(tdir2) or { panic(err) } + os.mkdir(tdir1) or { panic(err.msg) } + os.mkdir(tdir2) or { panic(err.msg) } // 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') assert os.exists(expected) && !is_dir(expected) == true // 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') assert os.exists(expected) && is_dir(expected) == true expected = os.join_path(tdir2, 'dir', 'file') assert os.exists(expected) && !is_dir(expected) == true // 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 assert os.exists(expected) && is_dir(expected) == true assert os.is_dir_empty(tdir2) == true // 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') assert os.exists(expected) && !is_dir(expected) == true // 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 assert os.exists(expected) && !is_dir(expected) == true } @@ -253,22 +253,22 @@ fn test_mv() { fn test_cp_all() { // fileX -> dir/fileX // NB: clean up of the files happens inside the cleanup_leftovers function - os.write_file('ex1.txt', 'wow!') or { panic(err) } - os.mkdir('ex') or { panic(err) } - os.cp_all('ex1.txt', 'ex', false) or { panic(err) } - old := os.read_file('ex1.txt') or { panic(err) } - new := os.read_file('ex/ex1.txt') or { panic(err) } + os.write_file('ex1.txt', 'wow!') or { panic(err.msg) } + os.mkdir('ex') or { panic(err.msg) } + os.cp_all('ex1.txt', 'ex', false) or { panic(err.msg) } + old := os.read_file('ex1.txt') or { panic(err.msg) } + new := os.read_file('ex/ex1.txt') or { panic(err.msg) } assert old == new - os.mkdir('ex/ex2') or { panic(err) } - os.write_file('ex2.txt', 'great!') or { panic(err) } - os.cp_all('ex2.txt', 'ex/ex2', false) or { panic(err) } - old2 := os.read_file('ex2.txt') or { panic(err) } - new2 := os.read_file('ex/ex2/ex2.txt') or { panic(err) } + os.mkdir('ex/ex2') or { panic(err.msg) } + os.write_file('ex2.txt', 'great!') or { panic(err.msg) } + os.cp_all('ex2.txt', 'ex/ex2', false) or { panic(err.msg) } + old2 := os.read_file('ex2.txt') or { panic(err.msg) } + new2 := os.read_file('ex/ex2/ex2.txt') or { panic(err.msg) } assert old2 == new2 // 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 - os.cp_all('ex', './', true) or { panic(err) } + os.cp_all('ex', './', true) or { panic(err.msg) } } fn test_realpath() { @@ -282,10 +282,10 @@ fn test_tmpdir() { tfile := t + os.path_separator + 'tmpfile.txt' os.rm(tfile) or { } // just in case tfile_content := 'this is a temporary file' - os.write_file(tfile, tfile_content) or { panic(err) } - tfile_content_read := os.read_file(tfile) or { panic(err) } + os.write_file(tfile, tfile_content) or { panic(err.msg) } + tfile_content_read := os.read_file(tfile) or { panic(err.msg) } assert tfile_content_read == tfile_content - os.rm(tfile) or { panic(err) } + os.rm(tfile) or { panic(err.msg) } } fn test_is_writable_folder() { @@ -307,13 +307,13 @@ fn test_make_symlink_check_is_link_and_remove_symlink() { symlink := 'tsymlink' os.rm(symlink) or { } os.rm(folder) or { } - os.mkdir(folder) or { panic(err) } - folder_contents := os.ls(folder) or { panic(err) } + os.mkdir(folder) or { panic(err.msg) } + folder_contents := os.ls(folder) or { panic(err.msg) } assert folder_contents.len == 0 os.system('ln -s $folder $symlink') assert os.is_link(symlink) == true - os.rm(symlink) or { panic(err) } - os.rm(folder) or { panic(err) } + os.rm(symlink) or { panic(err.msg) } + os.rm(folder) or { panic(err.msg) } folder_exists := os.is_dir(folder) assert folder_exists == false symlink_exists := os.is_link(symlink) @@ -345,12 +345,12 @@ fn test_symlink() { $if windows { return } - os.mkdir('symlink') or { panic(err) } - os.symlink('symlink', 'symlink2') or { panic(err) } + os.mkdir('symlink') or { panic(err.msg) } + os.symlink('symlink', 'symlink2') or { panic(err.msg) } assert os.exists('symlink2') // cleanup - os.rm('symlink') or { panic(err) } - os.rm('symlink2') or { panic(err) } + os.rm('symlink') or { panic(err.msg) } + os.rm('symlink2') or { panic(err.msg) } } fn test_is_executable_writable_readable() { @@ -373,7 +373,7 @@ fn test_is_executable_writable_readable() { assert os.is_executable(file_name) } // We finally delete the test file. - os.rm(file_name) or { panic(err) } + os.rm(file_name) or { panic(err.msg) } } fn test_ext() { @@ -457,8 +457,8 @@ fn test_write_file_array_bytes() { for i in 0 .. maxn { arr[i] = 65 + byte(i) } - os.write_file_array(fpath, arr) or { panic(err) } - rarr := os.read_bytes(fpath) or { panic(err) } + os.write_file_array(fpath, arr) or { panic(err.msg) } + rarr := os.read_bytes(fpath) or { panic(err.msg) } assert arr == rarr // eprintln(arr.str()) // eprintln(rarr.str()) @@ -470,7 +470,7 @@ fn test_write_file_array_structs() { for i in 0 .. maxn { 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(fpath) assert rarr == arr assert rarr.len == maxn diff --git a/vlib/readline/readline_test.v b/vlib/readline/readline_test.v index ab5154f38d..e50964657e 100644 --- a/vlib/readline/readline_test.v +++ b/vlib/readline/readline_test.v @@ -7,7 +7,7 @@ fn no_lines(s string) string { fn test_struct_readline() { // mut rl := Readline{} // 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') mut methods := []string{} $for method in Readline.methods { diff --git a/vlib/semver/range.v b/vlib/semver/range.v index eddd1b3c9e..3e519c0fa0 100644 --- a/vlib/semver/range.v +++ b/vlib/semver/range.v @@ -61,10 +61,10 @@ fn parse_range(input string) ?Range { mut comparator_sets := []ComparatorSet{} for raw_comp_set in raw_comparator_sets { 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 } 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 } } diff --git a/vlib/sqlite/sqlite_test.v b/vlib/sqlite/sqlite_test.v index ebcd3aa10a..47068ac7e8 100644 --- a/vlib/sqlite/sqlite_test.v +++ b/vlib/sqlite/sqlite_test.v @@ -5,7 +5,7 @@ fn test_sqlite() { return } mut db := sqlite.connect(':memory:') or { - panic(err) + panic(err.msg) } assert db.is_open db.exec('drop table if exists users') @@ -23,11 +23,11 @@ fn test_sqlite() { code = db.exec_none('vacuum') assert code == 101 user := db.exec_one('select * from users where id = 3') or { - panic(err) + panic(err.msg) } assert user.vals.len == 2 db.close() or { - panic(err) + panic(err.msg) } assert !db.is_open } diff --git a/vlib/term/ui/termios_nix.c.v b/vlib/term/ui/termios_nix.c.v index b2c0357e00..13050ccdc3 100644 --- a/vlib/term/ui/termios_nix.c.v +++ b/vlib/term/ui/termios_nix.c.v @@ -125,7 +125,7 @@ fn (mut ctx Context) termios_setup() ? { os.signal(C.SIGCONT, fn () { mut c := ctx_ptr 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() mut event := &Event{ typ: .resized diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 9f8b467941..813fcdb4f6 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -43,7 +43,7 @@ pub fn new_builder(pref &pref.Preferences) Builder { } msvc := find_msvc(pref.m64) or { if pref.ccompiler == 'msvc' { - verror('Cannot find MSVC on this OS') + // verror('Cannot find MSVC on this OS') } MsvcResult{ valid: false @@ -205,7 +205,7 @@ pub fn (b Builder) v_files_from_dir(dir string) []string { } else if !os.is_dir(dir) { 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 { println('v_files_from_dir ("$dir")') } diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index b0da21f188..c5c5598a30 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -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.info('build_c($out_file)') output2 := b.gen_c(v_files) - mut f := os.create(out_file) or { panic(err) } - f.writeln(output2) or { panic(err) } + mut f := os.create(out_file) or { panic(err.msg) } + f.writeln(output2) or { panic(err.msg) } f.close() 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') @@ -86,9 +86,9 @@ pub fn (mut b Builder) compile_c() { bundle_name := b.pref.out_name.split('/').last() 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 } - 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, - bundle_name, 1)) or { panic(err) } + bundle_name, 1)) or { panic(err.msg) } } b.cc() } diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 464752d3b7..a4d186906d 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -90,7 +90,7 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) { if v.pref.is_verbose { eprintln('>> remove tmp file: $tmpfile') } - os.rm(tmpfile) or { panic(err) } + os.rm(tmpfile) or { panic(err.msg) } } } return @@ -418,7 +418,7 @@ fn (mut v Builder) setup_output_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 { - panic(err) + panic(err.msg) } // 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 - 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 false @@ -481,7 +481,7 @@ fn (mut v Builder) dump_c_options(all_args []string) { if v.pref.dump_c_flags == '-' { print(non_empty_args) } 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 { os.Result{ exit_code: 111 - output: 'C compilation failed.\n$err' + output: 'C compilation failed.\n$err.msg' } } util.timing_measure(ccompiler_label) @@ -709,7 +709,7 @@ fn (mut v Builder) cc() { obj_file + ' /usr/lib/x86_64-linux-gnu/libc.so ' + '/usr/lib/x86_64-linux-gnu/crtn.o') or { - verror(err) + verror(err.msg) return } println(ress.output) @@ -759,7 +759,7 @@ fn (mut b Builder) cc_linux_cross() { b.setup_output_name() parent_dir := os.vmodules_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') if !os.is_dir(sysroot) { @@ -819,7 +819,7 @@ fn (mut b Builder) cc_linux_cross() { } res := os.exec(linker_cmd) or { println('Cross compilation for Linux failed (second step, lld).') - verror(err) + verror(err.msg) return } 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 // the best we can do for them is just copy them, // 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 } 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 { eprintln('exec failed for thirdparty object build cmd:\n$cmd') - verror(err) + verror(err.msg) return } os.chdir(current_folder) @@ -994,7 +994,7 @@ fn (mut v Builder) build_thirdparty_obj_file(path string, moduleflags []cflag.CF return } v.pref.cache_manager.save('.description.txt', obj_path, '${obj_path:-30} @ $cmd\n') or { - panic(err) + panic(err.msg) } println(res.output) } diff --git a/vlib/v/builder/compile.v b/vlib/v/builder/compile.v index c1776fe45c..82029cfdee 100644 --- a/vlib/v/builder/compile.v +++ b/vlib/v/builder/compile.v @@ -29,7 +29,7 @@ pub fn compile(command string, pref &pref.Preferences) { } os.is_writable_folder(output_folder) or { // An early error here, is better than an unclear C error later: - verror(err) + verror(err.msg) exit(1) } // 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 { 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() 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' } - os.exec('xcrun simctl launch $device $bundle_id') or { panic(err) } + os.exec('xcrun simctl launch $device $bundle_id') or { panic(err.msg) } } else { exefile := os.real_path(b.pref.out_name) mut cmd := '"$exefile"' @@ -133,7 +133,7 @@ fn (mut v Builder) cleanup_run_executable_after_exit(exefile string) { } if os.is_file(exefile) { v.pref.vrun_elog('remove run executable: $exefile') - os.rm(exefile) or { panic(err) } + os.rm(exefile) or { panic(err.msg) } } } diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index 6a5296b66a..a6ae08a749 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -34,8 +34,8 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) { b.out_name_js = out_file b.info('build_js($out_file)') output := b.gen_js(v_files) - mut f := os.create(out_file) or { panic(err) } - f.writeln(output) or { panic(err) } + mut f := os.create(out_file) or { panic(err.msg) } + f.writeln(output) or { panic(err.msg) } f.close() } @@ -58,7 +58,7 @@ fn (mut b Builder) run_js() { cmd := 'node ' + b.pref.out_name + '.js' res := os.exec(cmd) or { println('JS compilation failed.') - verror(err) + verror(err.msg) return } println(res.output) diff --git a/vlib/v/builder/msvc.v b/vlib/v/builder/msvc.v index 5ed4d6661e..b4ef5acf5d 100644 --- a/vlib/v/builder/msvc.v +++ b/vlib/v/builder/msvc.v @@ -329,7 +329,7 @@ pub fn (mut v Builder) cc_msvc() { // println(res) // println('C OUTPUT:') // 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) { @@ -369,7 +369,7 @@ fn (mut v Builder) build_thirdparty_obj_file_with_msvc(path string, moduleflags } res := os.exec(cmd) or { println('msvc: failed to execute msvc compiler (to build a thirdparty object); cmd: $cmd') - verror(err) + verror(err.msg) return } if res.exit_code != 0 { diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index d7c5199512..dc336ce851 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -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 { + inside_println_arg_save := c.inside_println_arg + c.inside_println_arg = true for i, expr in node.exprs { ftyp := c.expr(expr) 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.inside_println_arg = inside_println_arg_save return table.string_type } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e58a556251..0518f41c91 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2972,7 +2972,7 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type { if array_init.has_default { default_typ := c.expr(array_init.default_expr) 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 { @@ -3459,7 +3459,7 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { mut flag := node.main if flag.contains('@VROOT') { vroot := util.resolve_vroot(flag, c.file.path) or { - c.error(err, node.pos) + c.error(err.msg, node.pos) return } node.val = 'include $vroot' @@ -3468,7 +3468,7 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { } if flag.contains('\$env(') { env := util.resolve_env_value(flag, true) or { - c.error(err, node.pos) + c.error(err.msg, node.pos) return } node.main = env @@ -3486,15 +3486,15 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { '--cflags --libs $node.main'.split(' ') } mut m := pkgconfig.main(args) or { - c.error(err, node.pos) + c.error(err.msg, node.pos) return } cflags := m.run() or { - c.error(err, node.pos) + c.error(err.msg, node.pos) return } 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 } } 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 if flag.contains('@VROOT') { flag = util.resolve_vroot(flag, c.file.path) or { - c.error(err, node.pos) + c.error(err.msg, node.pos) return } } if flag.contains('\$env(') { flag = util.resolve_env_value(flag, true) or { - c.error(err, node.pos) + c.error(err.msg, node.pos) return } } @@ -3519,7 +3519,9 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { } } // 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 { if node.kind != 'define' { 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() } 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 { 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))) if node.is_env { 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 } 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) right_type := c.expr(cond.right) expr := c.find_definition(cond.left) or { - c.error(err, cond.left.pos) + c.error(err.msg, cond.left.pos) return false } 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 } expr := c.find_obj_definition(cond.obj) or { - c.error(err, cond.pos) + c.error(err.msg, cond.pos) return false } if !c.check_types(typ, table.bool_type) { diff --git a/vlib/v/checker/tests/return_optional_err.out b/vlib/v/checker/tests/return_optional_err.out index dd158fb65b..e7066fcfea 100644 --- a/vlib/v/checker/tests/return_optional_err.out +++ b/vlib/v/checker/tests/return_optional_err.out @@ -1,7 +1,7 @@ vlib/v/checker/tests/return_optional_err.vv:4:13: error: cannot use `?string` as type `string` in return argument 2 | 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 | } 6 | diff --git a/vlib/v/checker/tests/return_optional_err.vv b/vlib/v/checker/tests/return_optional_err.vv index 3bcda19257..03be0efe75 100644 --- a/vlib/v/checker/tests/return_optional_err.vv +++ b/vlib/v/checker/tests/return_optional_err.vv @@ -1,7 +1,7 @@ import os 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() { diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 071719085c..31ca3c70a2 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -239,14 +239,14 @@ fn (mut task TaskDescription) execute() { } program := task.path 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 task.expected_out_path = expected_out_path task.cli_cmd = cli_cmd 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.found___ = clean_line_endings(res.output) $if windows { @@ -257,7 +257,7 @@ fn (mut task TaskDescription) execute() { if task.expected != task.found___ { task.is_error = true 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 { - files := os.ls(dir) or { panic(err) } + files := os.ls(dir) or { panic(err.msg) } mut tests := files.clone() if !is_module { tests = files.filter(it.ends_with('.vv')) diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 9c168f3772..4e4086cb20 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -353,7 +353,7 @@ pub fn (mut d Doc) generate() ? { os.real_path(os.dir(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) if v_files.len == 0 { return error_with_code('vdoc: No valid V files were found.', 1) diff --git a/vlib/v/fmt/fmt_keep_test.v b/vlib/v/fmt/fmt_keep_test.v index 3b130ccc73..2d5330d290 100644 --- a/vlib/v/fmt/fmt_keep_test.v +++ b/vlib/v/fmt/fmt_keep_test.v @@ -67,7 +67,7 @@ fn test_fmt() { continue } 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)) continue } diff --git a/vlib/v/fmt/fmt_test.v b/vlib/v/fmt/fmt_test.v index a4a620c4e2..74ca947d10 100644 --- a/vlib/v/fmt/fmt_test.v +++ b/vlib/v/fmt/fmt_test.v @@ -59,7 +59,7 @@ fn test_fmt() { continue } 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)) continue } diff --git a/vlib/v/fmt/fmt_vlib_test.v b/vlib/v/fmt/fmt_vlib_test.v index 8e004db10c..7936c50adf 100644 --- a/vlib/v/fmt/fmt_vlib_test.v +++ b/vlib/v/fmt/fmt_vlib_test.v @@ -57,7 +57,7 @@ fn test_vlib_fmt() { continue } 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)) continue } diff --git a/vlib/v/fmt/tests/chan_ops_keep.vv b/vlib/v/fmt/tests/chan_ops_keep.vv index df3d3af1da..57ae61688a 100644 --- a/vlib/v/fmt/tests/chan_ops_keep.vv +++ b/vlib/v/fmt/tests/chan_ops_keep.vv @@ -16,7 +16,7 @@ fn get_val_from_chan(ch chan i64) ?i64 { fn get_val_from_chan2(ch chan i64) ?i64 { r := <-ch or { println('error') - return error(err) + return err } return r } diff --git a/vlib/v/fmt/tests/match_keep.vv b/vlib/v/fmt/tests/match_keep.vv index 3e8ee79b08..73326e4c37 100644 --- a/vlib/v/fmt/tests/match_keep.vv +++ b/vlib/v/fmt/tests/match_keep.vv @@ -34,13 +34,13 @@ fn branches_are_struct_inits() { fn branches_are_call_exprs_with_or_blocks() { match 'a' { - 'b' { foo() or { panic(err) } } + 'b' { foo() or { panic(err.msg) } } } match 'a' { 'b' { foo() or { // do stuff - panic(err) + panic(err.msg) } } } @@ -48,7 +48,7 @@ fn branches_are_call_exprs_with_or_blocks() { 'b' { foo() or { another_stmt() - panic(err) + panic(err.msg) } } } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index c9a7c4d954..28622bd387 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -648,7 +648,9 @@ static inline $opt_el_type __Option2_${styp}_popval($styp ch) { $opt_el_type _tmp = {0}; if (sync__Channel_try_pop_priv(ch, _tmp.data, false)) { Option2 _tmp2 = error2(_SLIT("channel closed")); - return *($opt_el_type*)&_tmp2; + $opt_el_type _tmp3; + memcpy(&_tmp3, &_tmp2, sizeof(Option2)); + return _tmp3; } 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) { if (sync__Channel_try_push_priv(ch, &e, false)) { Option2 _tmp2 = error2(_SLIT("channel closed")); - return *(Option2_void*)&_tmp2; + Option2_void _tmp3; + memcpy(&_tmp3, &_tmp2, sizeof(Option2)); + return _tmp3; } 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 { 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 { 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 );') @@ -5580,7 +5584,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table. } } else { // 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 // the defered statements are generated. g.write_defer_stmts() diff --git a/vlib/v/gen/c/cgen_test.v b/vlib/v/gen/c/cgen_test.v index 1aa5b5de50..b96a110ce8 100644 --- a/vlib/v/gen/c/cgen_test.v +++ b/vlib/v/gen/c/cgen_test.v @@ -18,7 +18,7 @@ fn test_c_files() { vroot := os.dir(vexe) for i in 1 .. (nr_tests + 1) { 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{}) b.module_search_paths = ['$vroot/vlib/v/gen/tests/'] mut res := b.gen_c([path]).after('#endbuiltin') diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 567960adb2..bfd46d4f54 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -237,7 +237,7 @@ fn (mut g Gen) comp_if_cond(cond ast.Expr) bool { } ast.PostfixExpr { ifdef := g.comp_if_to_ifdef((cond.expr as ast.Ident).name, true) or { - verror(err) + verror(err.msg) return false } g.write('defined($ifdef)') diff --git a/vlib/v/gen/js/jsgen_test.v b/vlib/v/gen/js/jsgen_test.v index 2115b8fb68..d1d8ee561a 100644 --- a/vlib/v/gen/js/jsgen_test.v +++ b/vlib/v/gen/js/jsgen_test.v @@ -15,7 +15,7 @@ const there_is_node_available = is_nodejs_working() fn test_example_compilation() { vexe := os.getenv('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() for file in files { path := os.join_path(test_dir, file) @@ -40,7 +40,7 @@ fn test_example_compilation() { } 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 mut tests := files.filter(it.ends_with('.v')).filter(it != 'life.v') tests.sort() diff --git a/vlib/v/gen/js/tests/js.v b/vlib/v/gen/js/tests/js.v index 0722e9f5d2..b8d9a6bd1e 100644 --- a/vlib/v/gen/js/tests/js.v +++ b/vlib/v/gen/js/tests/js.v @@ -88,7 +88,7 @@ fn main() { println(message) }) hl.raw_js_log() - propagation() or { println(err) } + propagation() or { println(err.msg) } } fn anon_consumer(greeting string, anon fn (message string)) { diff --git a/vlib/v/gen/x64/elf.v b/vlib/v/gen/x64/elf.v index 5ffbc73d25..4cf598b63b 100644 --- a/vlib/v/gen/x64/elf.v +++ b/vlib/v/gen/x64/elf.v @@ -99,7 +99,7 @@ pub fn (mut g Gen) generate_elf_footer() { // -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) // 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 unsafe { f.write_bytes(g.buf.data, g.buf.len) } f.close() diff --git a/vlib/v/gen/x64/tests/x64_test.v b/vlib/v/gen/x64/tests/x64_test.v index c1905481f8..296c90f29b 100644 --- a/vlib/v/gen/x64/tests/x64_test.v +++ b/vlib/v/gen/x64/tests/x64_test.v @@ -15,10 +15,10 @@ fn test_x64() { vexe := os.getenv('VEXE') vroot := os.dir(vexe) 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') - os.mkdir_all(wrkdir) or { panic(err) } + os.mkdir_all(wrkdir) or { panic(err.msg) } os.chdir(wrkdir) tests := files.filter(it.ends_with('.vv')) if tests.len == 0 { @@ -46,7 +46,7 @@ fn test_x64() { eprintln(res.output) 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') mut found := res.output.trim_right('\r\n').replace('\r\n', '\n') found = found.trim_space() diff --git a/vlib/v/live/live_test.v b/vlib/v/live/live_test.v index 816d44ee0a..85ef59c47c 100644 --- a/vlib/v/live/live_test.v +++ b/vlib/v/live/live_test.v @@ -44,7 +44,7 @@ const ( ) 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) } @@ -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, // 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. - os.write_file(tmp_file, source) or { panic(err) } - os.mv(tmp_file, source_file) or { panic(err) } + os.write_file(tmp_file, source) or { panic(err.msg) } + os.mv(tmp_file, source_file) or { panic(err.msg) } } // diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 72e0218f47..a3fe12025e 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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) // println('parse_file("$path")') // text := os.read_file(path) or { - // panic(err) + // panic(err.msg) // } mut p := Parser{ scanner: scanner.new_scanner_file(path, comments_mode, pref) diff --git a/vlib/v/pkgconfig/main.v b/vlib/v/pkgconfig/main.v index 3f53995aea..cc27cc77e6 100644 --- a/vlib/v/pkgconfig/main.v +++ b/vlib/v/pkgconfig/main.v @@ -83,7 +83,7 @@ pub fn (mut m Main) run() ?string { for arg in opt.args { mut pcdep := load(arg, options) or { if !opt.exists { - return error(err) + return err } continue } diff --git a/vlib/v/pkgconfig/pkgconfig.v b/vlib/v/pkgconfig/pkgconfig.v index 3e7e004a49..2b16aa16de 100644 --- a/vlib/v/pkgconfig/pkgconfig.v +++ b/vlib/v/pkgconfig/pkgconfig.v @@ -245,7 +245,7 @@ pub fn load(pkgname string, options Options) ?&PkgConfig { options: options } pc.load_paths() - file := pc.resolve(pkgname) or { return error(err) } + file := pc.resolve(pkgname) or { return err } if !pc.parse(file) { return error('file "$file" could not be parsed') } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 86513a5e54..a2558a0b19 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -488,7 +488,7 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences os.rm(tmp_exe_file_path) or { } } res.vrun_elog('remove tmp v file: $tmp_v_file_path') - os.rm(tmp_v_file_path) or { panic(err) } + os.rm(tmp_v_file_path) or { panic(err.msg) } exit(tmp_result) } must_exist(res.path) diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 6ae1e2207e..5e2b1f025b 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -281,7 +281,7 @@ pub fn (t &Table) find_field(s &TypeSymbol, name string) ?Field { if field := ts.info.find_field(name) { return field } - field := t.register_aggregate_field(mut ts, name) or { return error(err) } + field := t.register_aggregate_field(mut ts, name) or { return err } return field } else if mut ts.info is Interface { if field := ts.info.find_field(name) { diff --git a/vlib/v/tests/anon_fn_returning_question_test.v b/vlib/v/tests/anon_fn_returning_question_test.v index 36cd2732d8..5e5f443e09 100644 --- a/vlib/v/tests/anon_fn_returning_question_test.v +++ b/vlib/v/tests/anon_fn_returning_question_test.v @@ -1,7 +1,7 @@ type FnCb = fn (a string, b int) ? fn test_calling_an_anon_function_returning_question() { - create_and_call_anon_function() or { panic(err) } + create_and_call_anon_function() or { panic(err.msg) } } fn create_and_call_anon_function() ? { diff --git a/vlib/v/tests/inout/compiler_test.v b/vlib/v/tests/inout/compiler_test.v index 86277527b6..80c4bf08c1 100644 --- a/vlib/v/tests/inout/compiler_test.v +++ b/vlib/v/tests/inout/compiler_test.v @@ -16,25 +16,25 @@ fn test_all() { os.chdir(vroot) diff_cmd := util.find_working_diff_command() or { '' } dir := 'vlib/v/tests/inout' - files := os.ls(dir) or { panic(err) } + files := os.ls(dir) or { panic(err.msg) } tests := files.filter(it.ends_with('.vv')) if tests.len == 0 { println('no compiler tests found') assert false } - paths := vtest.filter_vtest_only(tests, + paths := vtest.filter_vtest_only(tests, basepath: dir ) for path in paths { print(path + ' ') program := path - compilation := os.exec('$vexe -o test -cflags "-w" -cg $program') or { panic(err) } + compilation := os.exec('$vexe -o test -cflags "-w" -cg $program') or { panic(err.msg) } if compilation.exit_code != 0 { panic('compilation failed: $compilation.output') } res := os.exec('./test') or { println('nope') - panic(err) + panic(err.msg) } $if windows { os.rm('./test.exe') or { } @@ -49,7 +49,7 @@ fn test_all() { // println(res.output) // println('============') mut found := res.output.trim_right('\r\n').replace('\r\n', '\n') - 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 = expected.trim_right('\r\n').replace('\r\n', '\n') if expected.contains('================ V panic ================') { // panic include backtraces and absolute file paths, so can't do char by char comparison diff --git a/vlib/v/tests/inout/os.vv b/vlib/v/tests/inout/os.vv index 9d8d423364..32b353e104 100644 --- a/vlib/v/tests/inout/os.vv +++ b/vlib/v/tests/inout/os.vv @@ -3,7 +3,7 @@ import os fn main() { vexe := os.getenv('VEXE') vroot := os.dir(vexe) - mut files := os.ls(vroot) or { panic(err) } + mut files := os.ls(vroot) or { panic(err.msg) } files.sort() for file in files { if file.ends_with('.md') { diff --git a/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v b/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v index 0212027941..e184ee86b4 100644 --- a/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v +++ b/vlib/v/tests/multiple_paths_in_vmodules/vmodules_overrides_test.v @@ -18,7 +18,7 @@ fn test_vexe_is_set() { fn test_compiling_without_vmodules_fails() { os.chdir(vroot) os.setenv('VMODULES', '', true) - res := os.exec('"$vexe" run "$mainvv"') or { panic(err) } + res := os.exec('"$vexe" run "$mainvv"') or { panic(err.msg) } assert res.exit_code == 1 assert res.output.trim_space().contains('builder error: cannot import module "yyy" (not found)') } @@ -27,7 +27,7 @@ fn test_compiling_with_vmodules_works() { os.chdir(vroot) vmpaths := ['path1', 'path2', 'path3'].map(os.join_path(basepath, it)) os.setenv('VMODULES', vmpaths.join(os.path_delimiter), true) - res := os.exec('"$vexe" run "$mainvv"') or { panic(err) } + res := os.exec('"$vexe" run "$mainvv"') or { panic(err.msg) } assert res.exit_code == 0 assert res.output.trim_space() == "['x', 'y', 'z']" } diff --git a/vlib/v/tests/option_test.v b/vlib/v/tests/option_test.v index d48237060a..968b6a99ff 100644 --- a/vlib/v/tests/option_test.v +++ b/vlib/v/tests/option_test.v @@ -84,7 +84,7 @@ fn for_opt_default() ?string { fn test_opt_default() { a := for_opt_default() or { - // panic(err) + // panic(err.msg) 'default' } assert a == 'default' @@ -258,7 +258,7 @@ fn multi_return_opt(err bool) (string, string) { fn test_multi_return_opt() { a, b := multi_return_opt(false) or { - panic(err) + panic(err.msg) } assert a == 'hello' && b == 'v' _, _ := multi_return_opt(true) or { diff --git a/vlib/v/tests/orm_sub_struct_test.v b/vlib/v/tests/orm_sub_struct_test.v index 2fde0f63f3..8eba69f5b8 100644 --- a/vlib/v/tests/orm_sub_struct_test.v +++ b/vlib/v/tests/orm_sub_struct_test.v @@ -11,7 +11,7 @@ struct SubStruct { } fn test_orm_sub_structs() { - db := sqlite.connect(':memory:') or { panic(err) } + db := sqlite.connect(':memory:') or { panic(err.msg) } db.exec('create table Upper (id integer primary key, sub int default 0)') db.exec('create table SubStruct (id integer primary key, name string default "")') @@ -30,4 +30,4 @@ fn test_orm_sub_structs() { } assert upper_s.sub.name == upper_1.sub.name -} \ No newline at end of file +} diff --git a/vlib/v/tests/prod_test.v b/vlib/v/tests/prod_test.v index a59ca946a7..4eac10da01 100644 --- a/vlib/v/tests/prod_test.v +++ b/vlib/v/tests/prod_test.v @@ -15,7 +15,7 @@ fn test_all_v_prod_files() { bmark.step() fres := runner.run_prod_file(options.wd, options.vexec, file) or { bmark.fail() - eprintln(bmark.step_message_fail(err)) + eprintln(bmark.step_message_fail(err.msg)) assert false continue } diff --git a/vlib/v/tests/repl/repl_test.v b/vlib/v/tests/repl/repl_test.v index 7f277ce1b8..347f7d3379 100644 --- a/vlib/v/tests/repl/repl_test.v +++ b/vlib/v/tests/repl/repl_test.v @@ -12,11 +12,11 @@ fn test_the_v_compiler_can_be_invoked() { println('vexecutable: $vexec') assert vexec != '' vcmd := '"$vexec" -version' - r := os.exec(vcmd) or { panic(err) } + r := os.exec(vcmd) or { panic(err.msg) } // println('"$vcmd" exit_code: $r.exit_code | output: $r.output') assert r.exit_code == 0 vcmd_error := '"$vexec" nonexisting.v' - r_error := os.exec(vcmd_error) or { panic(err) } + r_error := os.exec(vcmd_error) or { panic(err.msg) } // println('"$vcmd_error" exit_code: $r_error.exit_code | output: $r_error.output') assert r_error.exit_code == 1 actual_error := r_error.output.trim_space() @@ -36,7 +36,7 @@ fn test_all_v_repl_files() { } // warmup, and ensure that the vrepl is compiled in single threaded mode if it does not exist runner.run_repl_file(os.cache_dir(), session.options.vexec, 'vlib/v/tests/repl/nothing.repl') or { - panic(err) + panic(err.msg) } session.bmark.set_total_expected_steps(session.options.files.len) mut pool_repl := pool.new_pool_processor( @@ -64,23 +64,23 @@ fn worker_repl(mut p pool.PoolProcessor, idx int, thread_id int) voidptr { tls_bench.cstep = idx tfolder := os.join_path(cdir, 'vrepl_tests_$idx') if os.is_dir(tfolder) { - os.rmdir_all(tfolder) or { panic(err) } + os.rmdir_all(tfolder) or { panic(err.msg) } } - os.mkdir(tfolder) or { panic(err) } + os.mkdir(tfolder) or { panic(err.msg) } file := p.get_item(idx) session.bmark.step() tls_bench.step() fres := runner.run_repl_file(tfolder, session.options.vexec, file) or { session.bmark.fail() tls_bench.fail() - os.rmdir_all(tfolder) or { panic(err) } - eprintln(tls_bench.step_message_fail(err)) + os.rmdir_all(tfolder) or { panic(err.msg) } + eprintln(tls_bench.step_message_fail(err.msg)) assert false return pool.no_result } session.bmark.ok() tls_bench.ok() - os.rmdir_all(tfolder) or { panic(err) } + os.rmdir_all(tfolder) or { panic(err.msg) } println(tls_bench.step_message_ok(fres)) assert true return pool.no_result diff --git a/vlib/v/tests/repl/run.v b/vlib/v/tests/repl/run.v index 7f7fcc3452..498e432713 100644 --- a/vlib/v/tests/repl/run.v +++ b/vlib/v/tests/repl/run.v @@ -13,7 +13,7 @@ fn main() { bmark.step() fres := runner.run_repl_file(options.wd, options.vexec, file) or { bmark.fail() - logger.error(bmark.step_message_fail(err)) + logger.error(bmark.step_message_fail(err.msg)) continue } bmark.ok() diff --git a/vlib/v/tests/repl/runner/runner.v b/vlib/v/tests/repl/runner/runner.v index 4ec542475e..8e6b4984a1 100644 --- a/vlib/v/tests/repl/runner/runner.v +++ b/vlib/v/tests/repl/runner/runner.v @@ -47,22 +47,22 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string { output := content.all_after('===output===\n').trim_right('\n\r') fname := os.file_name(file) input_temporary_filename := os.real_path(os.join_path(wd, 'input_temporary_filename.txt')) - os.write_file(input_temporary_filename, input) or { panic(err) } - os.write_file(os.real_path(os.join_path(wd, 'original.txt')), fcontent) or { panic(err) } + os.write_file(input_temporary_filename, input) or { panic(err.msg) } + os.write_file(os.real_path(os.join_path(wd, 'original.txt')), fcontent) or { panic(err.msg) } rcmd := '"$vexec" repl -replfolder "$wd" -replprefix "${fname}." < $input_temporary_filename' r := os.exec(rcmd) or { - os.rm(input_temporary_filename) or { panic(err) } + os.rm(input_temporary_filename) or { panic(err.msg) } return error('Could not execute: $rcmd') } - os.rm(input_temporary_filename) or { panic(err) } + os.rm(input_temporary_filename) or { panic(err.msg) } result := r.output.replace('\r', '').replace('>>> ', '').replace('>>>', '').replace('... ', '').replace(wd + os.path_separator, '').replace(vexec_folder, '').replace('\\', '/').trim_right('\n\r') if result != output { file_result := '${file}.result.txt' file_expected := '${file}.expected.txt' - os.write_file(file_result, result) or { panic(err) } - os.write_file(file_expected, output) or { panic(err) } + os.write_file(file_result, result) or { panic(err.msg) } + os.write_file(file_expected, output) or { panic(err.msg) } diff := diff_files(file_expected, file_result) return error('Difference found in REPL file: $file ====> Expected : @@ -91,7 +91,7 @@ pub fn run_prod_file(wd string, vexec string, file string) ?string { result := r.output.replace('\r', '') if result != expected_content { file_result := '${file}.result.txt' - os.write_file(file_result, result) or { panic(err) } + os.write_file(file_result, result) or { panic(err.msg) } diff := diff_files(file_result, file_expected) return error('Difference found in test: $file ====> Got : diff --git a/vlib/v/tests/run_v_code_from_stdin_test.v b/vlib/v/tests/run_v_code_from_stdin_test.v index fde6f33444..327369c51c 100644 --- a/vlib/v/tests/run_v_code_from_stdin_test.v +++ b/vlib/v/tests/run_v_code_from_stdin_test.v @@ -19,10 +19,10 @@ fn pipe_to_v_run() ? { // eprintln('>> cmd: $cmd | res: $res') assert res.exit_code == 0 assert res.output.replace('\r', '').trim_space().split('\n') == ['4', 'hello'] - os.rm(tmp_v_file) or { panic(err) } + os.rm(tmp_v_file) or { panic(err.msg) } assert !os.exists(tmp_v_file) } fn test_pipe_to_v_run() { - pipe_to_v_run() or { panic(err) } + pipe_to_v_run() or { panic(err.msg) } } diff --git a/vlib/v/tests/valgrind/valgrind_test.v b/vlib/v/tests/valgrind/valgrind_test.v index c3110e93c1..b4e0790c54 100644 --- a/vlib/v/tests/valgrind/valgrind_test.v +++ b/vlib/v/tests/valgrind/valgrind_test.v @@ -50,10 +50,10 @@ fn test_all() { vroot := os.dir(vexe) valgrind_test_path := 'vlib/v/tests/valgrind' dir := os.join_path(vroot, valgrind_test_path) - files := os.ls(dir) or { panic(err) } + files := os.ls(dir) or { panic(err.msg) } // wrkdir := os.join_path(os.temp_dir(), 'vtests', 'valgrind') - os.mkdir_all(wrkdir) or { panic(err) } + os.mkdir_all(wrkdir) or { panic(err.msg) } os.chdir(wrkdir) // only_ordinary_v_files := files.filter(it.ends_with('.v') && !it.ends_with('_test.v')) diff --git a/vlib/v/tests/vargs_empty_param_test.v b/vlib/v/tests/vargs_empty_param_test.v index c89eceeb09..03cbcbf6a6 100644 --- a/vlib/v/tests/vargs_empty_param_test.v +++ b/vlib/v/tests/vargs_empty_param_test.v @@ -14,7 +14,7 @@ fn new(config Config, shard_count ...int) ?&Client { fn test_can_compile_an_empty_var_arg() { x := new(Config{ token: 'xyz' - }) or { panic(err) } + }) or { panic(err.msg) } assert x.x == 1 assert x.y == 2 } diff --git a/vlib/v/tests/vmod_parser_test.v b/vlib/v/tests/vmod_parser_test.v index e8db9d9bae..141caf0ef7 100644 --- a/vlib/v/tests/vmod_parser_test.v +++ b/vlib/v/tests/vmod_parser_test.v @@ -3,7 +3,7 @@ import os fn test_from_file() { os.chdir(os.dir(os.getenv('VEXE'))) - data := vmod.from_file('./v.mod') or { panic(err) } + data := vmod.from_file('./v.mod') or { panic(err.msg) } assert data.name == 'V' assert data.description == 'The V programming language.' //assert data.version == '0.2.1' diff --git a/vlib/v/util/diff.v b/vlib/v/util/diff.v index 90fe7c8c25..1c46a365db 100644 --- a/vlib/v/util/diff.v +++ b/vlib/v/util/diff.v @@ -64,10 +64,10 @@ pub fn color_compare_strings(diff_cmd string, expected string, found string) str ctime := time.sys_mono_now() e_file := os.join_path(cdir, '${ctime}.expected.txt') f_file := os.join_path(cdir, '${ctime}.found.txt') - os.write_file(e_file, expected) or { panic(err) } - os.write_file(f_file, found) or { panic(err) } + os.write_file(e_file, expected) or { panic(err.msg) } + os.write_file(f_file, found) or { panic(err.msg) } res := color_compare_files(diff_cmd, e_file, f_file) - os.rm(e_file) or { panic(err) } - os.rm(f_file) or { panic(err) } + os.rm(e_file) or { panic(err.msg) } + os.rm(f_file) or { panic(err.msg) } return res } diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 28d1c11a17..1a8bc53ed8 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -214,7 +214,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { if should_compile { emodules := util.external_module_dependencies_for_tool[tool_name] for emodule in emodules { - check_module_is_installed(emodule, is_verbose) or { panic(err) } + check_module_is_installed(emodule, is_verbose) or { panic(err.msg) } } mut compilation_command := '"$vexe" ' if tool_name in ['vself', 'vup', 'vdoctor', 'vsymlink'] { @@ -229,7 +229,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { if is_verbose { println('Compiling $tool_name with: "$compilation_command"') } - tool_compilation := os.exec(compilation_command) or { panic(err) } + tool_compilation := os.exec(compilation_command) or { panic(err.msg) } if tool_compilation.exit_code != 0 { eprintln('cannot compile `$tool_source`: \n$tool_compilation.output') exit(1) @@ -462,7 +462,7 @@ pub fn ensure_modules_for_all_tools_are_installed(is_verbose bool) { eprintln('Installing modules for tool: $tool_name ...') } for emodule in tool_modules { - check_module_is_installed(emodule, is_verbose) or { panic(err) } + check_module_is_installed(emodule, is_verbose) or { panic(err.msg) } } } } @@ -535,7 +535,7 @@ pub fn get_vtmp_folder() string { } vtmp = os.join_path(os.temp_dir(), 'v') if !os.exists(vtmp) || !os.is_dir(vtmp) { - os.mkdir_all(vtmp) or { panic(err) } + os.mkdir_all(vtmp) or { panic(err.msg) } } os.setenv('VTMP', vtmp, true) return vtmp diff --git a/vlib/v/vcache/vcache.v b/vlib/v/vcache/vcache.v index aa958460a0..e2914f5130 100644 --- a/vlib/v/vcache/vcache.v +++ b/vlib/v/vcache/vcache.v @@ -41,13 +41,15 @@ pub fn new_cache_manager(opts []string) CacheManager { } dlog(@FN, 'vcache_basepath: $vcache_basepath | opts:\n $opts') if !os.is_dir(vcache_basepath) { - os.mkdir_all(vcache_basepath) or { panic(err) } + os.mkdir_all(vcache_basepath) or { panic(err.msg) } readme_content := 'This folder contains cached build artifacts from the V build system. |You can safely delete it, if it is getting too large. |It will be recreated the next time you compile something with V. |You can change its location with the VCACHE environment variable. '.strip_margin() - os.write_file(os.join_path(vcache_basepath, 'README.md'), readme_content) or { panic(err) } + os.write_file(os.join_path(vcache_basepath, 'README.md'), readme_content) or { + panic(err.msg) + } } original_vopts := opts.join('|') return CacheManager{ @@ -76,7 +78,7 @@ pub fn (mut cm CacheManager) key2cpath(key string) string { cprefix_folder := os.join_path(cm.basepath, prefix) cpath = os.join_path(cprefix_folder, khash) if !os.is_dir(cprefix_folder) { - os.mkdir_all(cprefix_folder) or { panic(err) } + os.mkdir_all(cprefix_folder) or { panic(err.msg) } os.chmod(cprefix_folder, 0o777) } dlog(@FN, 'new hk') diff --git a/vlib/vweb/assets/assets.v b/vlib/vweb/assets/assets.v index 1240e4123c..7124941c40 100644 --- a/vlib/vweb/assets/assets.v +++ b/vlib/vweb/assets/assets.v @@ -96,10 +96,10 @@ fn (am AssetManager) combine(asset_type string, to_file bool) string { return out } if !os.is_dir(am.cache_dir) { - os.mkdir(am.cache_dir) or { panic(err) } + os.mkdir(am.cache_dir) or { panic(err.msg) } } - mut file := os.create(out_file) or { panic(err) } - file.write(out.bytes()) or { panic(err) } + mut file := os.create(out_file) or { panic(err.msg) } + file.write(out.bytes()) or { panic(err.msg) } file.close() return out_file } diff --git a/vlib/vweb/assets/assets_test.v b/vlib/vweb/assets/assets_test.v index 6170f3ce47..7b3dead8af 100644 --- a/vlib/vweb/assets/assets_test.v +++ b/vlib/vweb/assets/assets_test.v @@ -6,7 +6,7 @@ import os // unique cache dirs are needed per test function. fn clean_cache_dir(dir string) { if os.is_dir(dir) { - os.rmdir_all(dir) or { panic(err) } + os.rmdir_all(dir) or { panic(err.msg) } } } @@ -21,10 +21,10 @@ fn cache_dir(test_name string) string { fn get_test_file_path(file string) string { path := os.join_path(base_cache_dir(), file) if !os.is_dir(base_cache_dir()) { - os.mkdir_all(base_cache_dir()) or { panic(err) } + os.mkdir_all(base_cache_dir()) or { panic(err.msg) } } if !os.exists(path) { - os.write_file(path, get_test_file_contents(file)) or { panic(err) } + os.write_file(path, get_test_file_contents(file)) or { panic(err.msg) } } return path } diff --git a/vlib/vweb/tests/vweb_test.v b/vlib/vweb/tests/vweb_test.v index dc8f7a5530..93cff318ac 100644 --- a/vlib/vweb/tests/vweb_test.v +++ b/vlib/vweb/tests/vweb_test.v @@ -102,14 +102,14 @@ fn assert_common_http_headers(x http.Response) { } fn test_http_client_index() { - x := http.get('http://127.0.0.1:$sport/') or { panic(err) } + x := http.get('http://127.0.0.1:$sport/') or { panic(err.msg) } assert_common_http_headers(x) assert x.headers['Content-Type'] == 'text/plain' assert x.text == 'Welcome to VWeb' } fn test_http_client_chunk_transfer() { - x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err) } + x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err.msg) } assert_common_http_headers(x) assert x.headers['Transfer-Encoding'] == 'chunked' assert x.text == 'Lorem ipsum dolor sit amet, consetetur sadipscing' @@ -122,45 +122,45 @@ fn test_http_client_404() { 'http://127.0.0.1:$sport/unknown', ] for url in url_404_list { - res := http.get(url) or { panic(err) } + res := http.get(url) or { panic(err.msg) } assert res.status_code == 404 } } fn test_http_client_simple() { - x := http.get('http://127.0.0.1:$sport/simple') or { panic(err) } + x := http.get('http://127.0.0.1:$sport/simple') or { panic(err.msg) } assert_common_http_headers(x) assert x.headers['Content-Type'] == 'text/plain' assert x.text == 'A simple result' } fn test_http_client_html_page() { - x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err) } + x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err.msg) } assert_common_http_headers(x) assert x.headers['Content-Type'] == 'text/html' assert x.text == '

ok

' } fn test_http_client_settings_page() { - x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err) } + x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err.msg) } assert_common_http_headers(x) assert x.text == 'username: bilbo' // - y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err) } + y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err.msg) } assert_common_http_headers(y) assert y.text == 'username: kent' } fn test_http_client_user_repo_settings_page() { - x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err) } + x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err.msg) } assert_common_http_headers(x) assert x.text == 'username: bilbo | repository: gostamp' // - y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err) } + y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err.msg) } assert_common_http_headers(y) assert y.text == 'username: kent | repository: golang' // - z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err) } + z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err.msg) } assert z.status_code == 404 } @@ -175,7 +175,9 @@ fn test_http_client_json_post() { age: 123 } json_for_ouser := json.encode(ouser) - mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) } + mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { + panic(err.msg) + } $if debug_net_socket_client ? { eprintln('/json_echo endpoint response: $x') } @@ -184,7 +186,7 @@ fn test_http_client_json_post() { nuser := json.decode(User, x.text) or { User{} } assert '$ouser' == '$nuser' // - x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) } + x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err.msg) } $if debug_net_socket_client ? { eprintln('/json endpoint response: $x') } @@ -236,7 +238,7 @@ fn simple_tcp_client(config SimpleTcpClientConfig) ?string { tries++ client = net.dial_tcp('127.0.0.1:$sport') or { if tries > config.retries { - return error(err) + return err } time.sleep(100 * time.millisecond) continue diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 268169846b..8c67dcea1e 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -594,7 +594,7 @@ pub fn (mut ctx Context) parse_multipart_form(s string, b string) { } fn (mut ctx Context) scan_static_directory(directory_path string, mount_path string) { - files := os.ls(directory_path) or { panic(err) } + files := os.ls(directory_path) or { panic(err.msg) } if files.len > 0 { for file in files { full_path := directory_path + '/' + file diff --git a/vlib/x/ttf/common.v b/vlib/x/ttf/common.v index 4c91ccf935..7c72d3e998 100644 --- a/vlib/x/ttf/common.v +++ b/vlib/x/ttf/common.v @@ -93,17 +93,17 @@ pub fn (mut bmp BitMap) save_as_ppm(file_name string) { bmp.format_texture() npixels := bmp.width * bmp.height - mut f_out := os.create(file_name) or { panic(err) } - f_out.writeln('P3') or { panic(err) } - f_out.writeln('$bmp.width $bmp.height') or { panic(err) } - f_out.writeln('255') or { panic(err) } + mut f_out := os.create(file_name) or { panic(err.msg) } + f_out.writeln('P3') or { panic(err.msg) } + f_out.writeln('$bmp.width $bmp.height') or { panic(err.msg) } + f_out.writeln('255') or { panic(err.msg) } for i in 0 .. npixels { pos := i * bmp.bp unsafe { c_r := bmp.buf[pos] c_g := bmp.buf[pos + 1] c_b := bmp.buf[pos + 2] - f_out.write_str('$c_r $c_g $c_b ') or { panic(err) } + f_out.write_str('$c_r $c_g $c_b ') or { panic(err.msg) } } } f_out.close() @@ -127,7 +127,7 @@ pub fn (mut bmp BitMap) get_raw_bytes() []byte { } pub fn (mut bmp BitMap) save_raw_data(file_name string) { - os.write_file_array(file_name, bmp.get_raw_bytes()) or { panic(err) } + os.write_file_array(file_name, bmp.get_raw_bytes()) or { panic(err.msg) } } // diff --git a/vlib/x/ttf/ttf_test.v b/vlib/x/ttf/ttf_test.v index d62dbf773d..837c322d9b 100644 --- a/vlib/x/ttf/ttf_test.v +++ b/vlib/x/ttf/ttf_test.v @@ -156,13 +156,13 @@ fn save_raw_data_as_array(buf_bin []byte, file_name string) { for x in buf_bin { buf.write_string('0x${x:02x},') } - os.write_file_array(file_name, buf.buf) or { panic(err) } + os.write_file_array(file_name, buf.buf) or { panic(err.msg) } } fn test_main() { mut tf := ttf.TTF_File{} $if create_data ? { - tf.buf = os.read_bytes(font_path) or { panic(err) } + tf.buf = os.read_bytes(font_path) or { panic(err.msg) } println('TrueTypeFont file [$font_path] len: $tf.buf.len') save_raw_data_as_array(tf.buf, 'test_ttf_Font_arr.bin') } $else { @@ -200,7 +200,7 @@ fn test_main() { $if create_data ? { bmp.save_as_ppm('test_ttf.ppm') bmp.save_raw_data('test_ttf.bin') - test_buf = os.read_bytes('test_ttf.bin') or { panic(err) } + test_buf = os.read_bytes('test_ttf.bin') or { panic(err.msg) } } ram_buf := bmp.get_raw_bytes() diff --git a/vlib/x/websocket/io.v b/vlib/x/websocket/io.v index 6b02791496..c24f887fd4 100644 --- a/vlib/x/websocket/io.v +++ b/vlib/x/websocket/io.v @@ -18,7 +18,7 @@ fn (mut ws Client) socket_read(mut buffer []byte) ?int { if err.code == net.err_timed_out_code { continue } - return error(err) + return err } return r } @@ -42,7 +42,7 @@ fn (mut ws Client) socket_read_ptr(buf_ptr byteptr, len int) ?int { if err.code == net.err_timed_out_code { continue } - return error(err) + return err } return r } @@ -66,7 +66,7 @@ fn (mut ws Client) socket_write(bytes []byte) ?int { if err.code == net.err_timed_out_code { continue } - return error(err) + return err } return n } diff --git a/vlib/x/websocket/message.v b/vlib/x/websocket/message.v index ec843e635f..ce530bd4c0 100644 --- a/vlib/x/websocket/message.v +++ b/vlib/x/websocket/message.v @@ -148,7 +148,7 @@ pub fn (mut ws Client) read_next_message() ?Message { ws.validate_utf_8(frame.opcode, frame_payload) or { ws.logger.error('UTF8 validation error: $err, len of payload($frame_payload.len)') ws.send_error_event('UTF8 validation error: $err, len of payload($frame_payload.len)') - return error(err) + return err } msg := Message{ opcode: OPCode(frame.opcode) diff --git a/vlib/x/websocket/tests/autobahn/autobahn_client.v b/vlib/x/websocket/tests/autobahn/autobahn_client.v index 6b94e7fd67..7228428e08 100644 --- a/vlib/x/websocket/tests/autobahn/autobahn_client.v +++ b/vlib/x/websocket/tests/autobahn/autobahn_client.v @@ -29,5 +29,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? { // We just wanna pass text and binary message back to autobahn return } - ws.write(msg.payload, msg.opcode) or { panic(err) } + ws.write(msg.payload, msg.opcode) or { panic(err.msg) } } diff --git a/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v b/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v index 7d015ea9e8..5886d40e95 100644 --- a/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v +++ b/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v @@ -31,5 +31,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? { // We just wanna pass text and binary message back to autobahn return } - ws.write(msg.payload, msg.opcode) or { panic(err) } + ws.write(msg.payload, msg.opcode) or { panic(err.msg) } } diff --git a/vlib/x/websocket/tests/autobahn/autobahn_server.v b/vlib/x/websocket/tests/autobahn/autobahn_server.v index d6b41dceb2..e8b6455179 100644 --- a/vlib/x/websocket/tests/autobahn/autobahn_server.v +++ b/vlib/x/websocket/tests/autobahn/autobahn_server.v @@ -6,7 +6,7 @@ import x.websocket fn main() { mut s := websocket.new_server(9002, '/') s.on_message(on_message) - s.listen() or { panic(err) } + s.listen() or { panic(err.msg) } } fn handle_case(case_nr int) ? { @@ -23,5 +23,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? { // We just wanna pass text and binary message back to autobahn return } - ws.write(msg.payload, msg.opcode) or { panic(err) } + ws.write(msg.payload, msg.opcode) or { panic(err.msg) } } diff --git a/vlib/x/websocket/tests/autobahn/local_run/autobahn_client.v b/vlib/x/websocket/tests/autobahn/local_run/autobahn_client.v index 1d29e27b07..e9b77ab081 100644 --- a/vlib/x/websocket/tests/autobahn/local_run/autobahn_client.v +++ b/vlib/x/websocket/tests/autobahn/local_run/autobahn_client.v @@ -29,5 +29,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? { // We just wanna pass text and binary message back to autobahn return } - ws.write(msg.payload, msg.opcode) or { panic(err) } + ws.write(msg.payload, msg.opcode) or { panic(err.msg) } } diff --git a/vlib/x/websocket/tests/autobahn/local_run/autobahn_client_wss.v b/vlib/x/websocket/tests/autobahn/local_run/autobahn_client_wss.v index 7d015ea9e8..5886d40e95 100644 --- a/vlib/x/websocket/tests/autobahn/local_run/autobahn_client_wss.v +++ b/vlib/x/websocket/tests/autobahn/local_run/autobahn_client_wss.v @@ -31,5 +31,5 @@ fn on_message(mut ws websocket.Client, msg &websocket.Message) ? { // We just wanna pass text and binary message back to autobahn return } - ws.write(msg.payload, msg.opcode) or { panic(err) } + ws.write(msg.payload, msg.opcode) or { panic(err.msg) } } diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index e1f62654fb..0bfcfc0093 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -121,7 +121,7 @@ pub fn (mut ws Client) listen() ? { } ws.debug_log('failed to read next message: $err') ws.send_error_event('failed to read next message: $err') - return error(err) + return err } if ws.state in [.closed, .closing] { return @@ -146,7 +146,7 @@ pub fn (mut ws Client) listen() ? { ws.logger.error('error in message callback sending PONG: $err') ws.send_error_event('error in message callback sending PONG: $err') if ws.panic_on_callback { - panic(err) + panic(err.msg) } continue } diff --git a/vlib/x/websocket/websocket_server.v b/vlib/x/websocket/websocket_server.v index 3475d4ce8a..f2f9b6563c 100644 --- a/vlib/x/websocket/websocket_server.v +++ b/vlib/x/websocket/websocket_server.v @@ -120,8 +120,8 @@ fn (mut s Server) serve_client(mut c Client) ? { } s.setup_callbacks(mut server_client) c.listen() or { - s.logger.error(err) - return error(err) + s.logger.error(err.msg) + return err } } diff --git a/vlib/x/websocket/websocket_test.v b/vlib/x/websocket/websocket_test.v index 7e222f8e5e..7a0773c742 100644 --- a/vlib/x/websocket/websocket_test.v +++ b/vlib/x/websocket/websocket_test.v @@ -40,8 +40,8 @@ fn start_server(listen_port int) ? { }) ? s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? { match msg.opcode { - .pong { ws.write_str('pong') or { panic(err) } } - else { ws.write(msg.payload, msg.opcode) or { panic(err) } } + .pong { ws.write_str('pong') or { panic(err.msg) } } + else { ws.write(msg.payload, msg.opcode) or { panic(err.msg) } } } })