Skip to content
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

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

Open
goldfirere opened this issue Feb 4, 2022 · 14 comments
Open

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

goldfirere opened this issue Feb 4, 2022 · 14 comments
Labels
type: enhancement New feature or request

Comments

@goldfirere
Copy link

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 goldfirere added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Feb 4, 2022
@goldfirere
Copy link
Author

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. :(

@pepeiborra
Copy link
Collaborator

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

@goldfirere
Copy link
Author

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
Copy link
Author

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! :)

@pepeiborra
Copy link
Collaborator

@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.

@goldfirere
Copy link
Author

@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 haskell/vscode-haskell#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.

@fendor
Copy link
Collaborator

fendor commented Mar 3, 2022

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

@kokobd kokobd added type: enhancement New feature or request and removed status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Sep 7, 2022
@tomjaguarpaw
Copy link
Member

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)

@fendor
Copy link
Collaborator

fendor commented Jan 14, 2023

@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?

@tomjaguarpaw
Copy link
Member

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").

@fendor
Copy link
Collaborator

fendor commented Jan 14, 2023

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.

@tomjaguarpaw
Copy link
Member

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

@isovector
Copy link
Collaborator

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

@fendor
Copy link
Collaborator

fendor commented Jan 27, 2023

@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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants