cairo
cairo copied to clipboard
bug: Cairo LS fails to obtain scarb corelib path from manifest file
Bug Report
Cairo version: >= 2.6.0
Current behavior:
When loading a Scarb project, the Cairo LS throws the below error:
2024-03-26T14:16:16.083874Z WARN cairo_lang_language_server: Failed to obtain scarb corelib path from manifest file.
Caused by:
0: Obtaining Scarb metadata for corelib path.
1: Failed to obtain Scarb metadata.
2: `scarb metadata` exited with error
stdout:
{"type":"error","message":"could not execute process: git clone --local --config core.autocrlf=false --recurse-submodules /home/boyuanxu/.cache/scarb/registry/git/db/cairo-contracts-9cboa8jg3jldq.git /home/boyuanxu/.cache/scarb/registry/git/checkouts/cairo-contracts-9cboa8jg3jldq/d770827\n\nCaused by:\n No such file or directory (os error 2)"}
stderr:
2024-03-26T14:16:16.083923Z WARN cairo_lang_language_server: Failed to find corelib path.
2024-03-26T14:16:16.094782Z WARN cairo_lang_language_server: Failed to obtain scarb metadata from manifest file.
Caused by:
0: Obtaining Scarb metadata for crate roots.
1: Failed to obtain Scarb metadata.
2: `scarb metadata` exited with error
stdout:
{"type":"error","message":"could not execute process: git clone --local --config core.autocrlf=false --recurse-submodules /home/boyuanxu/.cache/scarb/registry/git/db/cairo-contracts-9cboa8jg3jldq.git /home/boyuanxu/.cache/scarb/registry/git/checkouts/cairo-contracts-9cboa8jg3jldq/d770827\n\nCaused by:\n No such file or directory (os error 2)"}
stderr:
SemanticTokenKind recovery failed. Failed to find module.
SemanticTokenKind recovery failed. Failed to find module.
Expected behavior:
Cairo LS loads normally.
Steps to reproduce:
Load any Scarb project in WSL.
Related code:
[package]
name = "xxx"
version = "0.0.1"
edition = "2023_11"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html
[dependencies]
starknet = ">=2.6.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria" }
[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.20.1" }
[[target.starknet-contract]]
casm = true
Other information:
Cairo plugin version 2.6.3 Scarb version 2.6.4
~~I have found that if I used the LS I compiled myself, it will work fine. If I used the one bundled with Scarb, it will throw the above errors.~~
Hi @boyuanx !
Can you please try removing your Scarb cache with scarb cache clean
and then trying again?
The error message seems to indicate that the cache might get corrupted, as Scarb is unable to load a dependency there. Does it build for you when you run scarb build
?
Hi @boyuanx !
Can you please try removing your Scarb cache with
scarb cache clean
and then trying again?The error message seems to indicate that the cache might get corrupted, as Scarb is unable to load a dependency there. Does it build for you when you run
scarb build
?
Running scarb cache clean
makes no difference, unfortunately. Running scarb build
works fine, this issue seems limited to the LS. Currently it works randomly maybe 1 out of 10 launches, even when the LS path is set in the extension settings.
I seem to have found a pattern. I am able to reliably avoid this issue by opening a project in VSCode with an editor window that's not Cairo and then switch back to a Cairo file after a second or two. Is this some sort of race condition?
On the other hand, if I remove the LS path from extension settings, I receive the following error:
[error] Error: could not find CairoLS on this machine
I was under the impression that setting the path is optional.
The error message suggests that CairoLS run via VSCode Remote Server cannot find git
executable, while apparently scarb
ran from the CLI can. I have no idea how this could be non-deterministic, though. Do you have some unusual Git setup on your box?
The error message suggests that CairoLS run via VSCode Remote Server cannot find
git
executable, while apparentlyscarb
ran from the CLI can. I have no idea how this could be non-deterministic, though. Do you have some unusual Git setup on your box?
No, it's vanilla WSL 2 on a new laptop.
Thanks for the info. I need to reproduce this locally to be able to determine what could be wrong from now on. Unfortunately, I have no spare time to do this right now, so I have to park this issue in the backlog 😞
I want to soonish rewrite the logic of handling Scarb and cairo_project.toml
file (to fix #5354). There's a chance that I'll resolve this problem accidentally also. I will reach out to you to retest when this rewrite will be released.
@mkaput Whatever you did between the marketplace 2.6.3 release and the current repo build, this bug is gone on my end. If I revert to the marketplace 2.6.3, I get this issue again.
TBH I don't see any commits that could change anything related to this, see history for the extension.
Nonetheless, I'm relieved to hear that this is now working for you!