commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.99k stars 845 forks source link

Add an option like --exec that only runs on a failed build? #3819

Open JonnyRa opened 6 years ago

JonnyRa commented 6 years ago

Hi,

Maybe I'm going about this the wrong way but trying to get the errors from stack into my editor:

I'm doing a inotifywait -m -o logschanged -e modify .stack-work/logs/ which watches the logs and records the files that have changed (these will contain the errors).

The output of that just looks like:

...
.stack-work/logs/ MODIFY model-0.0.0.log
.stack-work/logs/ MODIFY model-0.0.0.log
...

I was then hoping to run something like this stack build --exec 'awk '!seen[$0]++' logschanged | grep "error\|warn" > .errors '

for when the build has finished (but failed)

which gets rid of the duplicates from the logs changed and then filters out just the error and warning lines... looks like this:

src/Types/BlahBlah.hs:20:39: error:
src/Types/Blah.hs:25:37: error:
src/Types/Err.hs:6:5: error:
src/Types/BlahErr.hs:20:5: error:

I think using this plugin from vim would then let you go straight to the right file and line number from that file... which would be pretty awesome.

Its not fully finished yet - the logschanged file needs periodically deleting but would allow a much speedier way of fixing errors when refactoring.

So what I'd like to do is add an option like --exec-fail 'blah' that is just like exec but runs on failure of the build rather than success.

I'd be happy to implement it if you can point me in the right direction.

Cheers

Jonny

JonnyRa commented 6 years ago

BTW I'm using --file-watch for my build(s) so can't just look at the error code and branch on that as stack is running things

dpwiz commented 6 years ago

That was very helpful in my yesod times. Missing it in stack build --file-watch...

mgsloan commented 6 years ago

Hmm, seems reasonable.

I'd be happy to implement it if you can point me in the right direction.

Great! Here are some spots in the code related to --exec:

The CLI part of this would probably be the same as --exec. However, it would probably catch errors out at the Main.hs level. One defail of semantics is whether --exec-fail would get run if one of the --exec actions fails. Based on having an exception handler in Main, I think it would.

JonnyRa commented 6 years ago

Cool, thanks. I'm off on holiday next week + busy this week but I might have chance to look at it towards the end of the month.

Sounds potentially more useful + general purpose to run on any error, even though maybe it's overloading it a bit, maybe we can throw in some information about what exe/part of the process the error has come from aswell if it's fairly easy so external scripts can switch on that

JonnyRa commented 5 years ago

Hi! I never got around to looking at this + not sure I'm mega bothered about implementing it now so thought I'd close the issue. Thanks for your response :)

dpwiz commented 5 years ago

Please reopen? I would still be glad to have a way to notify me about build failures.

JonnyRa commented 5 years ago

No problem