1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: panic with error message when go command fails (#10943)

This commit is contained in:
Uwe Krüger
2021-07-25 00:13:34 +02:00
committed by GitHub
parent a09324faa9
commit 55c5b9ce7b
7 changed files with 70 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ module builtin
type FnExitCb = fn ()
fn C.atexit(f FnExitCb) int
fn C.strerror(int) &char
[noreturn]
fn vhalt() {
@@ -100,6 +101,28 @@ pub fn panic(s string) {
vhalt()
}
// return a C-API error message matching to `errnum`
pub fn c_error_number_str(errnum int) string {
mut err_msg := ''
$if freestanding {
err_msg = 'error $errnum'
} $else {
c_msg := C.strerror(errnum)
err_msg = string{
str: &byte(c_msg)
len: unsafe { C.strlen(c_msg) }
is_lit: 1
}
}
return err_msg
}
// panic with a C-API error message matching `errnum`
[noreturn]
pub fn panic_error_number(basestr string, errnum int) {
panic(basestr + c_error_number_str(errnum))
}
// eprintln prints a message with a line end, to stderr. Both stderr and stdout are flushed.
pub fn eprintln(s string) {
if s.str == 0 {