summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2018-12-27 13:46:53 -0800
committerAndreas Rumpf <rumpf_a@web.de>2018-12-27 22:46:53 +0100
commiteba8ffcf70cca5dd802c5d33f6ecea814829f9fc (patch)
tree6def7f07d26365de3f5d690a95b433208eacfa98
parentcc4720fac18ba0d9bacdb386cacb409632a5e1a6 (diff)
downloadNim-eba8ffcf70cca5dd802c5d33f6ecea814829f9fc.tar.gz
`checkErr` now shows actual system error msg instead of unknown error (#9987)
-rw-r--r--lib/system/sysio.nim17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 20964b166..5b0278d74 100644
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -74,10 +74,21 @@ proc raiseEIO(msg: string) {.noinline, noreturn.} =
 proc raiseEOF() {.noinline, noreturn.} =
   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) =
-  if c_ferror(f) != 0:
-    c_clearerr(f)
-    raiseEIO("Unknown IO Error")
+  when not defined(NimScript):
+    if c_ferror(f) != 0:
+      let msg = "errno: " & $errno & " `" & $strerror(errno) & "`"
+      c_clearerr(f)
+      raiseEIO(msg)
+  else:
+    # shouldn't happen
+    quit(1)
 
 {.push stackTrace:off, profiler:off.}
 proc readBuffer(f: File, buffer: pointer, len: Natural): int =