diff --git a/compiler/parser.v b/compiler/parser.v index ab814b856f..7ba70d6145 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -3855,6 +3855,7 @@ fn (p mut Parser) assert_statement() { if (!$tmp) { println(tos2((byte *)"\\x1B[31mFAILED: $p.cur_fn.name() in $filename:$p.scanner.line_nr\\x1B[0m")); g_test_fails++; + return; // TODO // Maybe print all vars in a test function if it fails? } else { diff --git a/vlib/http/backend_nix.v b/vlib/http/backend_nix.v index fedafce01f..cc8163932b 100644 --- a/vlib/http/backend_nix.v +++ b/vlib/http/backend_nix.v @@ -32,7 +32,7 @@ fn init() int { return 1 } -fn (req &Request) ssl_do(port int, method, host_name, path string) Response { +fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response { //ssl_method := C.SSLv23_method() ssl_method := C.TLSv1_2_method() if isnil(method) { diff --git a/vlib/http/backend_win.v b/vlib/http/backend_win.v index a7e1d9a587..d67f7baf49 100644 --- a/vlib/http/backend_win.v +++ b/vlib/http/backend_win.v @@ -16,7 +16,7 @@ fn C.new_tls_context() C.TlsContext fn init() int { return 1 } -fn (req &Request) ssl_do(port int, method, host_name, path string) Response { +fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response { mut ctx := C.new_tls_context() C.vschannel_init(&ctx) diff --git a/vlib/http/http.v b/vlib/http/http.v index ba9b428ae3..8493be3d3f 100644 --- a/vlib/http/http.v +++ b/vlib/http/http.v @@ -39,14 +39,20 @@ pub fn get(url string) ?Response { req := new_request('GET', url, '') or { return error(err) } - return req.do() + res := req.do() or { + return error(err) + } + return res } pub fn post(url, data string) ?Response { req := new_request('POST', url, data) or { return error(err) } - return req.do() + res := req.do() or { + return error(err) + } + return res } pub fn new_request(typ, _url, _data string) ?Request { @@ -151,10 +157,16 @@ fn (req &Request) method_and_url_to_response(method string, url net_dot_urllib.U //println('fetch $method, $scheme, $host_name, $nport, $path ') if scheme == 'https' { //println('ssl_do( $nport, $method, $host_name, $path )') - return req.ssl_do( nport, method, host_name, path ) + res := req.ssl_do( nport, method, host_name, path ) or { + return error(err) + } + return res } else if scheme == 'http' { //println('http_do( $nport, $method, $host_name, $path )') - return req.http_do(nport, method, host_name, path ) + res := req.http_do(nport, method, host_name, path ) or { + return error(err) + } + return res } return error('http.request.do: unsupported scheme: $scheme') } diff --git a/vlib/net/init_nix.v b/vlib/net/init_nix.v index 4caced4df7..cb447f734e 100644 --- a/vlib/net/init_nix.v +++ b/vlib/net/init_nix.v @@ -4,5 +4,10 @@ module net #include #include #include +#include fn init() int { return 1 } + +fn error_code() int { + return C.errno +} diff --git a/vlib/net/init_win.v b/vlib/net/init_win.v index 1155e7fbd8..de8e6f2f5c 100644 --- a/vlib/net/init_win.v +++ b/vlib/net/init_win.v @@ -29,3 +29,7 @@ fn init() int { return 1 } +fn error_code() int { + return C.WSAGetLastError() +} + diff --git a/vlib/net/socket.v b/vlib/net/socket.v index 7b18dab78a..d480866af0 100644 --- a/vlib/net/socket.v +++ b/vlib/net/socket.v @@ -1,5 +1,7 @@ module net +import os + struct Socket { pub: sockfd int @@ -162,11 +164,13 @@ pub fn (s Socket) connect(address string, port int) ?int { sport := '$port' info_res := C.getaddrinfo(address.str, sport.str, &hints, &info) if info_res != 0 { - return error('socket: connect failed') + error_message := os.get_error_msg(net.error_code()) + return error('socket: getaddrinfo failed ($error_message)') } res := int(C.connect(s.sockfd, info.ai_addr, info.ai_addrlen)) if res < 0 { - return error('socket: connect failed') + error_message := os.get_error_msg(net.error_code()) + return error('socket: connect failed ($error_message)') } return int(res) }