checkErr now shows actual system error msg instead of unknown error (#9987)
This commit is contained in:
parent
cc4720fac1
commit
eba8ffcf70
1 changed files with 14 additions and 3 deletions
|
|
@ -74,10 +74,21 @@ proc raiseEIO(msg: string) {.noinline, noreturn.} =
|
||||||
proc raiseEOF() {.noinline, noreturn.} =
|
proc raiseEOF() {.noinline, noreturn.} =
|
||||||
sysFatal(EOFError, "EOF reached")
|
sysFatal(EOFError, "EOF reached")
|
||||||
|
|
||||||
|
proc strerror(errnum: cint): cstring {.importc, header: "<string.h>".}
|
||||||
|
|
||||||
|
when not defined(NimScript):
|
||||||
|
var
|
||||||
|
errno {.importc, header: "<errno.h>".}: cint ## error variable
|
||||||
|
|
||||||
proc checkErr(f: File) =
|
proc checkErr(f: File) =
|
||||||
if c_ferror(f) != 0:
|
when not defined(NimScript):
|
||||||
c_clearerr(f)
|
if c_ferror(f) != 0:
|
||||||
raiseEIO("Unknown IO Error")
|
let msg = "errno: " & $errno & " `" & $strerror(errno) & "`"
|
||||||
|
c_clearerr(f)
|
||||||
|
raiseEIO(msg)
|
||||||
|
else:
|
||||||
|
# shouldn't happen
|
||||||
|
quit(1)
|
||||||
|
|
||||||
{.push stackTrace:off, profiler:off.}
|
{.push stackTrace:off, profiler:off.}
|
||||||
proc readBuffer(f: File, buffer: pointer, len: Natural): int =
|
proc readBuffer(f: File, buffer: pointer, len: Natural): int =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue