Closed dandevelo closed 5 years ago
As of devel build 2039dad2736909a9d2091b137eeab4293b508e12, try
/ except
seems to work.
Below example:
# Create a new directory and save this snippet as config.nims.
# Then run `nim debug`.
task debug, "Builds the debug version":
echo "This is the debug build"
try:
exec("./foo")
except:
echo "error happened"
setCommand("nop")
outputs:
This is the debug build
sh: ./foo: No such file or directory
error happened
But if we try to get details about the exception it does not work.
So below:
# Create a new directory and save this snippet as config.nims.
# Then run `nim debug`.
task debug, "Builds the debug version":
echo "This is the debug build"
try:
exec("./foo")
except:
echo "[Error] " & getCurrentException().name & ": " & getCurrentException().msg
setCommand("nop")
results in this error:
config.nims(3, 6) template/generic instantiation of `task` from here
config.nims(8, 23) Error: undeclared identifier: 'getCurrentException'
So may be the issue should be retitled to:
getCurrentException() does not work in Nimscript
On the other hand, if getCurrentException()
is designed to not get imported in Nimscripts, then this issue can be closed.
/cc @Araq
/cc @genotrance (copying you because I think https://github.com/nim-lang/Nim/issues/10240 was probably related to this?)
You should be able to use gorgeEx()
in nimscript.
Meanwhile, we can consider exposing getCurrentException()
.
You should be able to use gorgeEx() in nimscript.
Awesome! gorgeEx
works.
Below code:
task debug, "Builds the debug version":
echo "This is the debug build"
for cmd in @["./foo", "ls"]:
let
(outStr, errCode) = gorgeEx(cmd)
echo "cmd: " & cmd
echo "output string: " & outStr
echo "error code: " & $errCode
echo ""
setCommand("nop")
outputs:
This is the debug build
cmd: ./foo
output string: /bin/sh: ./foo: No such file or directory
error code: 127
cmd: ls
output string: config.nims
error code: 0
Meanwhile, we can consider exposing getCurrentException().
👍
I am trying to check for the result of the build step execution in order to run the app only if the build succeeded and run some custom code in case it didn't.
I have this code in a nimble task:
This fails with:
Is there another way to check for the exec result in nimscript?