-
Notifications
You must be signed in to change notification settings - Fork 347
Fix logic for running cabal directly. #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I do not think I am able to follow... anybody else understands if this is good pr or bad pr? @mdorman: Are you able to create an automated test in our testsuite to catch this issue? That would help a lot. |
@gracjan I assume the test environment doesn't have cabal installed? |
No, it does not. |
I think this test demonstrates the problem, as well as demonstrating that my fix resolves it. |
Hmm, I think |
@fice-t my change isn't only wrapping haskell-interactive-process, it's also wrapping process-status, which we don't have the luxury of changing. Still, while I don't think your suggestion is unreasonable from an engineering standpoint, it would cause a lot of churn for very little real value: look at all the callers of haskell-interactive-process---none of them check the return value, presumably because they expect it to throw an error if there's nothing present. So I'm not inclined to go down that road. The road I would consider if people preferred it, would be to restructure haskell-process-do-cabal to have all of its machinations to get the process information wrapped in a single ignore-errors call---so you end up with something like: (let ((process (ignore-errors (...)))) But as I alluded to in my initial message, that ends up restructuring that function significantly---and that seemed a bit aggressive to do for my first ever PR to the project. |
Ah, I see. Looks like it'd be a bunch of work to fix that. In that case, does there need to be an |
@fice-t I don't have enough perspective to say; it's not clear to me that |
should be both sufficient and resilient in case we ever do start | ||
testing with cabal laying around." | ||
(haskell-process-do-cabal "help") | ||
(with-current-buffer "*Messages*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test, this is about what we want, to see that haskell-process-do-cabal
does something.
There is a nice way to intercept deep calls with el-mock
. We use it for example here:
(mocklet (((haskell-session-name "dummy-session") => "dumses1")) |
Use mocklet
to make sure execution path you want it really taken. Thanks!
haskell-process-do-cabal has code that attempts to run cabal directly when there is no current interactive haskell process. Unfortunately, it doesn't work. This test demonstrates the problem, calling haskell-process-do-cabal and checking the *Messages* buffer for the presence of the string it should output if it was going to run cabal directly. Instead you get an error about the lack of a session associated with the buffer.
I suspect this has been broken for a while (perhaps always). The failure stems from the fact that (haskell-interactive-process) throws an uncaught error if there is no interacive process, which aborts the function. If that is wrapped to mask the error, (process-status child) also throws an uncaught error, which aborts the function. Thus the direct cabal invocation code would never be reached. This is the least intrusive fix I can see---wrapping both calls with (ignore-errors), and not even checking (process-status) if we don't have a process. In manual testing it behaves as expected, running `cabal build`. A more extensive fix---which would rewrite the conditional logic to wrap all the dangerous bits in a single (ignore-errors)---would almost certainly swap positions of the indirect cabal invocation and the direct cabal invocation, so there would be much more churn. Still, it might produce a nicer overall result, if anyone wants to see that.
So I removed the probably-superfluous I also rewrote the test to verify that |
Thanks! |
To see the failure, start a fresh copy of emacs, load a .cabal file, M-x
haskell-process-cabal-build; while the logic in haskell-process-do-cabal
suggests that that should not require an interactive process, it
complains that there is no interactive process.
I suspect this has been broken for a while (perhaps always). The
failure stems from the fact that (haskell-interactive-process) throws an
uncaught error if there is no interacive process, which aborts the
function. If that is wrapped to mask the error, (process-status child)
also throws an uncaught error, which aborts the function.
Thus the direct cabal invocation code would never be reached.
This is the least intrusive fix I can see---wrapping both calls
with (ignore-errors), and not even checking (process-status) if we don't
have a process. In manual testing it behaves as expected, running
cabal build
.A more extensive fix---which would rewrite the conditional logic to wrap
all the dangerous bits in a single (ignore-errors)---would almost
certainly swap positions of the indirect cabal invocation and the direct
cabal invocation, so there would be much more churn. Still, it might
produce a nicer overall result, if anyone wants to see that.