From 7bd2804ce932bdb8438e37a6a236dea85a561768 Mon Sep 17 00:00:00 2001 From: Maciej Obarski Date: Sat, 29 Aug 2020 01:58:03 +0200 Subject: [PATCH] all: automatic error propagation in place of "or { return(err) }" --- vlib/cli/flag.v | 24 ++++--------- vlib/crypto/rand/utils.v | 4 +-- vlib/encoding/csv/reader.v | 8 ++--- vlib/net/ftp/ftp.v | 4 +-- vlib/net/http/http.v | 24 ++++--------- vlib/net/http/http_httpbin_test.v | 8 ++--- vlib/net/socket.v | 20 +++-------- vlib/net/urllib/urllib.v | 52 +++++++--------------------- vlib/os/os.v | 40 ++++++--------------- vlib/pg/pg.v | 2 +- vlib/readline/readline.js.v | 12 ++----- vlib/readline/readline_darwin.c.v | 12 ++----- vlib/readline/readline_dragonfly.c.v | 12 ++----- vlib/readline/readline_freebsd.c.v | 12 ++----- vlib/readline/readline_linux.c.v | 12 ++----- vlib/readline/readline_netbsd.c.v | 12 ++----- vlib/readline/readline_openbsd.c.v | 12 ++----- vlib/readline/readline_solaris.c.v | 12 ++----- vlib/readline/readline_windows.c.v | 12 ++----- vlib/v/builder/msvc.v | 4 +-- vlib/v/vmod/parser.v | 8 ++--- vlib/vweb/tests/vweb_test.v | 4 +-- vlib/x/websocket/websocket_client.v | 4 +-- 23 files changed, 79 insertions(+), 235 deletions(-) diff --git a/vlib/cli/flag.v b/vlib/cli/flag.v index 64af6a2693..086dfb02c7 100644 --- a/vlib/cli/flag.v +++ b/vlib/cli/flag.v @@ -32,9 +32,7 @@ pub fn (flag Flag) get_bool() ?bool { } pub fn (flags []Flag) get_bool(name string) ?bool { - flag := flags.get(name) or { - return error(err) - } + flag := flags.get(name)? return flag.get_bool() } @@ -53,9 +51,7 @@ pub fn (flag Flag) get_int() ?int { } pub fn (flags []Flag) get_int(name string) ?int { - flag := flags.get(name) or { - return error(err) - } + flag := flags.get(name)? return flag.get_int() } @@ -74,9 +70,7 @@ pub fn (flag Flag) get_float() ?f64 { } pub fn (flags []Flag) get_float(name string) ?f64 { - flag := flags.get(name) or { - return error(err) - } + flag := flags.get(name)? return flag.get_float() } @@ -95,9 +89,7 @@ pub fn (flag Flag) get_string() ?string { } pub fn (flags []Flag) get_string(name string) ?string { - flag := flags.get(name) or { - return error(err) - } + flag := flags.get(name)? return flag.get_string() } @@ -112,14 +104,10 @@ pub fn (flags []Flag) get_string_or(name, or_value string) string { fn (mut flag Flag) parse(args []string, with_abbrev bool) ?[]string { if flag.matches(args, with_abbrev) { if flag.flag == .bool { - new_args := flag.parse_bool(args) or { - return error(err) - } + new_args := flag.parse_bool(args)? return new_args } else { - new_args := flag.parse_raw(args) or { - return error(err) - } + new_args := flag.parse_raw(args)? return new_args } } else { diff --git a/vlib/crypto/rand/utils.v b/vlib/crypto/rand/utils.v index 14796acb84..d5f852b026 100644 --- a/vlib/crypto/rand/utils.v +++ b/vlib/crypto/rand/utils.v @@ -19,9 +19,7 @@ pub fn int_u64(max u64) ?u64 { } mut n := u64(0) for { - mut bytes := read(k) or { - return error(err) - } + mut bytes := read(k)? bytes[0] &= byte(int(u64(1)< 1 { '?' + v[1] } else { '' } return &Uri{