haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

"Failed to parse result of calling cabal" on a M1 Mac

Open goldfirere opened this issue 3 years ago • 7 comments

Your environment

Which OS do you use: MacOS 12.2 on an M1 (aarch64) Mac. Which LSP client (editor/plugin) do you use: VSCode Describe your project (alternative: link to the project): https://github.com/goldfirere/video-resources/tree/main/2022-wordle

Steps to reproduce

I don't know how you can reproduce, but I can reliably reproduce the error by opening up a source file in my project in VSCode.

Expected behaviour

No error from the parsing the result of calling cabal.

Actual behaviour

I see this:

Failed to parse result of calling cabal
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - wordle-0.1.0.0 (exe:wordle) (first run)
Configuring executable 'wordle' for wordle-0.1.0.0..


/var/folders/mq/4sk7fqqs3tgggt70bhp2l7vh0000gn/T/ghc66101_0/ghc_1.s:3:41: error:
     error: unexpected token
            .globl  _foo                            ## -- Begin function foo
                                                    ^
  |
3 |         .globl  _foo                            ## -- Begin function foo
  |                                         ^

You can see this in action at https://youtu.be/C7-5y3sv_m4?t=527.

Include debug information

The log doesn't show me anything obviously interesting.

goldfirere avatar Feb 04 '22 15:02 goldfirere

Ready to film another video, and was hoping this would be fixed. I tried debugging a bit on my own to see if I could figure this out. When I run haskell-language-server-wrapper in the project directory, I indeed get the error above. Running cabal directly works fine, though.

At this point, it would be really helpful if there were a way to get HLS to print out what subcommands it is executing. Then, I might be able to spot how its interaction with cabal is going wrong. As it is now, all I can see is the output, but I don't know the input that's creating it. :(

goldfirere avatar Feb 11 '22 03:02 goldfirere

You are probably mixing x86 and arm binaries. HLS (hie-bios really) invokes cabal, so make sure that both are the same arch

pepeiborra avatar Feb 11 '22 07:02 pepeiborra

Sorry, but I'm not sure what you mean: are you worried about the arch of HLS? or hie-bios? or of cabal? I can find the HLS binary according to the instructions in the VSCode Haskell extension (which installed it for me). What about the hie-bios binary? I don't see it. And how do I query their arches? --version doesn't provide this information.

Maybe this will provide an answer, though: does HLS use the cabal that's in the PATH? That is, when I execute cabal myself, it all works fine. But when HLS does, bad things happen. Could it be that HLS is invoking a different cabal than I am? That might explain what I am seeing.

goldfirere avatar Feb 14 '22 01:02 goldfirere

Ping. I keep making videos without HLS. I miss HLS and my viewers are starting to tell me to turn it on. But I can't! Help! :)

goldfirere avatar Mar 02 '22 22:03 goldfirere

@goldfirere I don't have an M1 Mac to test, so I cannot answer questions like "how do I check their arches".

Please try to make sure that the haskell-language-server and cabal (or stack) binaries are the same arch. There is no other binary involved, specifically no hie-bios binary.

pepeiborra avatar Mar 03 '22 11:03 pepeiborra

@pepeiborra Thanks. I found https://stackoverflow.com/questions/1085137/how-do-i-determine-the-target-architecture-of-static-library-a-on-mac-os-x to help. (I had assumed I had to run e.g. haskell-language-server --what-arch-are-you to get the information. And I had further assumed that a binary of the wrong arch would simply fail to run. And I had assumed that the arch of the binary is unrelated to the action it takes when run. I think all of these were wrong.)

Indeed haskell-language-server is the wrong arch. A little more searching revealed https://github.com/haskell/vscode-haskell/issues/458, which is the underlying issue. That's the problem.

Is it worth keeping this ticket open as an opportunity for a more informative error message? Specifically, when HLS hits the "failed to parse the result of cabal" error, it could likely check the arch of the HLS binary and the machine's arch, reporting a very helpful error if they mismatch. If this is, say, too specialized, then please feel free to close the ticket.

goldfirere avatar Mar 03 '22 16:03 goldfirere

I think this issue will be solved once we merge https://github.com/haskell/vscode-haskell/pull/533 which installs the correct binaries based on the arch, afaict Although, better error message might be helpful anyway

fendor avatar Mar 03 '22 16:03 fendor

I've just hit this. It's strange because

  1. HLS is working fine on other modules in the same project. It doesn't work for the new one I just created.
  2. I am using GHC and HLS installed through ghcup, so there's no risk of binary incompatibility.

(I'm on Linux)

tomjaguarpaw avatar Jan 12 '23 19:01 tomjaguarpaw

@tomjaguarpaw What you describe sounds like a very different problem (especially since you are on linux).

Have these new modules been added to the cabal file? Until we have better integration with cabal files, there is a brief moment between creation and cabal modifications, where we try to load the module you have just added and there are not sensible cabal compiler options. In theory, when you wait, it should resolve by itself (but I think it is buggy). Restarting should always fix it, right?

fendor avatar Jan 14 '23 08:01 fendor

Oh, whoops, I forgot to add the new module to the cabal file.

A few points:

  • There should be a better diagnostic for this
  • I did, nonetheless, get the message "Failed to parse result of calling cabal". I don't know why I got that message, and this ticket is pretty much the only reference to that message. (That's what I meant by "I've just hit this", i.e. "this message").

tomjaguarpaw avatar Jan 14 '23 09:01 tomjaguarpaw

There should be a better diagnostic for this

Totally agree, but LSP has limited UX capabilities and cabal limited error reporting capability.

I don't know why I got that message

Because we internally invoke cabal repl src/File.hs and if it is not part of the project, ~~we can't parse it properly~~ we fail to parse the output from cabal (admittedly, we aren't even trying). We'd need much better error reporting from cabal to give better error messages.

fendor avatar Jan 14 '23 14:01 fendor

Thank you for the explanation, and thanks for your work on HLS. I love using it!

tomjaguarpaw avatar Jan 15 '23 09:01 tomjaguarpaw

I'm running into this also, but my modules are listed in the cabal file.

isovector avatar Jan 26 '23 21:01 isovector

@isovector Good morning!

Can you provide more logs? E.g. run hls on the cli, and provide the logs, e.g. haskell-language-server --debug <some-source-file>

fendor avatar Jan 27 '23 07:01 fendor