much better error message if an exe cannot be found
This commit is contained in:
parent
ace9299a32
commit
2297a1aa60
2 changed files with 6 additions and 3 deletions
|
|
@ -261,7 +261,7 @@ proc osErrorMsg*(errorCode: OSErrorCode): string =
|
||||||
if errorCode != OSErrorCode(0'i32):
|
if errorCode != OSErrorCode(0'i32):
|
||||||
result = $os.strerror(errorCode.int32)
|
result = $os.strerror(errorCode.int32)
|
||||||
|
|
||||||
proc raiseOSError*(errorCode: OSErrorCode) =
|
proc raiseOSError*(errorCode: OSErrorCode; additionalInfo = "") {.noinline.} =
|
||||||
## Raises an ``OSError`` exception. The ``errorCode`` will determine the
|
## Raises an ``OSError`` exception. The ``errorCode`` will determine the
|
||||||
## message, ``osErrorMsg`` will be used to get this message.
|
## message, ``osErrorMsg`` will be used to get this message.
|
||||||
##
|
##
|
||||||
|
|
@ -271,7 +271,10 @@ proc raiseOSError*(errorCode: OSErrorCode) =
|
||||||
## the message ``unknown OS error`` will be used.
|
## the message ``unknown OS error`` will be used.
|
||||||
var e: ref OSError; new(e)
|
var e: ref OSError; new(e)
|
||||||
e.errorCode = errorCode.int32
|
e.errorCode = errorCode.int32
|
||||||
e.msg = osErrorMsg(errorCode)
|
if additionalInfo.len == 0:
|
||||||
|
e.msg = osErrorMsg(errorCode)
|
||||||
|
else:
|
||||||
|
e.msg = additionalInfo & " " & osErrorMsg(errorCode)
|
||||||
if e.msg == "":
|
if e.msg == "":
|
||||||
e.msg = "unknown OS error"
|
e.msg = "unknown OS error"
|
||||||
raise e
|
raise e
|
||||||
|
|
|
||||||
|
|
@ -468,7 +468,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
fileClose(si.hStdError)
|
fileClose(si.hStdError)
|
||||||
|
|
||||||
if e != nil: dealloc(e)
|
if e != nil: dealloc(e)
|
||||||
if success == 0: raiseOSError(lastError)
|
if success == 0: raiseOSError(lastError, command)
|
||||||
# Close the handle now so anyone waiting is woken:
|
# Close the handle now so anyone waiting is woken:
|
||||||
discard closeHandle(procInfo.hThread)
|
discard closeHandle(procInfo.hThread)
|
||||||
result.fProcessHandle = procInfo.hProcess
|
result.fProcessHandle = procInfo.hProcess
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue