From ab7936f514aa1c62c72b54161d414ea2f8087038 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 5 Aug 2020 06:26:56 +0300 Subject: [PATCH] os.exec: on unix return error, when the command was not found, instead of os.Result --- vlib/os/os_nix.c.v | 6 +++--- vlib/os/os_windows.c.v | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index 1d3635abe1..648aa2affc 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -148,9 +148,9 @@ pub fn exec(cmd string) ?Result { soutput := res.str() // res.free() exit_code := vpclose(f) - // if exit_code != 0 { - // return error(res) - // } + if exit_code == 127 { + return error_with_code(soutput, 127) + } return Result{ exit_code: exit_code output: soutput diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index e108952661..78f4f9bec6 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -241,13 +241,15 @@ pub fn exec(cmd string) ?Result { create_pipe_ok := C.CreatePipe(voidptr(&child_stdout_read), voidptr(&child_stdout_write), voidptr(&sa), 0) if !create_pipe_ok { - error_msg := get_error_msg(int(C.GetLastError())) - return error('exec failed (CreatePipe): $error_msg') + error_num := int(C.GetLastError()) + error_msg := get_error_msg(error_num) + return error_with_code('exec failed (CreatePipe): $error_msg', error_num) } set_handle_info_ok := C.SetHandleInformation(child_stdout_read, C.HANDLE_FLAG_INHERIT, 0) if !set_handle_info_ok { - error_msg := get_error_msg(int(C.GetLastError())) - panic('exec failed (SetHandleInformation): $error_msg') + error_num := int(C.GetLastError()) + error_msg := get_error_msg(error_num) + return error_with_code('exec failed (SetHandleInformation): $error_msg', error_num) } proc_info := ProcessInformation{} @@ -267,7 +269,7 @@ pub fn exec(cmd string) ?Result { if !create_process_ok { error_num := int(C.GetLastError()) error_msg := get_error_msg(error_num) - return error('exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd') + return error_with_code('exec failed (CreateProcess) with code $error_num: $error_msg cmd: $cmd', error_num) } C.CloseHandle(child_stdin) C.CloseHandle(child_stdout_write)