nim-lang / nimble

Package manager for the Nim programming language.
https://nim-lang.github.io/nimble/index.html
Other
1.25k stars 191 forks source link

Returning an exit code from a task #634

Open bluenote10 opened 5 years ago

bluenote10 commented 5 years ago

Currently the task API doesn't seem to support exit codes. If a task encounters an error it can:

Maybe the task API could be extended so that it supports return <int> and Nimble forwards the code directly to quit without injecting a warning?

Araq commented 5 years ago

The "quit called" warning is out of place.

I like it and I think quit is what should be used. It's not out of place since otherwise debugging can be a nightmare. (How do I know? We used to lack this hint and the compiler would "die" and we didn't know why nor how nor where.)

bluenote10 commented 5 years ago

Agreed logging quit calls in the compiler makes sense, but for NimScript / Nimble there are use cases to exit gracefully without a message:

Supporting return <int> for Nimble tasks would achieve silent exists without the need to explicitly kill the script.

genotrance commented 5 years ago

Given nimble now just calls nim e behind the scenes, quit(1) now behaves differently.

raise newException() =>

> nimble one --verbose
    Reading config file at ~/.config/nimble/nimble.ini
  Executing task one in ~/programming/a/a.nimble
stack trace: (most recent call last)
/tmp/nimblecache/nimscriptapi.nim(164, 16)
~/programming/a/a_15029.nims(21, 3) oneTask
~/programming/a/a_15029.nims(21, 3) Error: unhandled exception: Exception text
     Error: ~/programming/nimbledevel/src/nimble.nim(1145) nimble
        ... ~/programming/nimbledevel/src/nimble.nim(1129) doAction
        ... ~/programming/nimbledevel/src/nimblepkg/nimscriptexecutor.nim(46) execCustom
        ... ~/programming/nimbledevel/src/nimblepkg/nimscriptwrapper.nim(164) execTask
        ... ~/programming/nimbledevel/src/nimblepkg/nimscriptwrapper.nim(135) execScript
        ... Exception raised during nimble script execution

quit(1) =>

> nimble one --verbose
    Reading config file at ~/.config/nimble/nimble.ini
  Executing task one in ~/programming/a/a.nimble
     Error: ~/programming/nimbledevel/src/nimble.nim(1145) nimble
        ... ~/programming/nimbledevel/src/nimble.nim(1129) doAction
        ... ~/programming/nimbledevel/src/nimblepkg/nimscriptexecutor.nim(46) execCustom
        ... ~/programming/nimbledevel/src/nimblepkg/nimscriptwrapper.nim(164) execTask
        ... ~/programming/nimbledevel/src/nimbl
dom96 commented 5 years ago

It seems quit(1) was broken, that sucks.

I actually disallow quit in Nimble's source code for the untraceability reason too and instead offer a NimbleQuit exception so you can always find which code wanted to quit. Personally I would like the same thing for the task API. What I really think we should do is create an RFC outlining precisely the API that the task API should have. I'm going to start the conversation in another issue.