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

Unable to compute dictionary path #251

Open
tekumara opened this issue Oct 29, 2024 · 10 comments
Open

Unable to compute dictionary path #251

tekumara opened this issue Oct 29, 2024 · 10 comments
Labels
bug Something isn't working good first issue Good for newcomers harper-ls

Comments

@tekumara
Copy link

tekumara commented Oct 29, 2024

Thread 'main' panicked at harper-ls/src/backend.rs:395:14:
called `Result::unwrap()` on an `Err` value: Unable to compute dictionary path.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Error - 20:48:54] Client Harper: connection to server is erroring.
write EPIPE
Shutting down server.
[Error - 20:48:54] Server process exited with code 101.
[Error - 20:48:54] Client Harper: connection to server is erroring.
Cannot call write after a stream was destroyed
[Error - 20:48:54] Connection to server got closed. Server will not be restarted.
[Error - 20:48:54] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 20:48:54] Stopping server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 20:48:54] Delivering pending changes failed

elijah-potter.harper-0.12.0-darwin-arm64

@tekumara tekumara changed the title Unable to compute dictionary path. Unable to compute dictionary path Oct 29, 2024
@grantlemons grantlemons added bug Something isn't working harper-ls labels Nov 13, 2024
@zoidyzoidzoid
Copy link

I'm getting the same bug.

I found a workaround, if you manually create harper-ls in the relevant config directory, that solves it!

In my case on MacOS I needed to do mkdir -p ~/Library/Application\ Support/harper-ls

Platform Value Example
Linux $XDG_CONFIG_HOME or $HOME/.config /home/alice/.config
macOS $HOME/Library/Application Support /Users/Alice/Library/Application Support
Windows {FOLDERID_RoamingAppData} C:\Users\Alice\AppData\Roaming

Stack trace

The save logic for the dictionary does create the intermediate directories as well, but the code isn't getting there, because the load doesn't support a missing user dictionary - https://sourcegraph.com/github.com/Automattic/harper/-/blob/harper-ls/src/dictionary_io.rs?L11

@zoidyzoidzoid
Copy link

This might be a good first issue for someone to fix this. 😅

@grantlemons
Copy link
Collaborator

I'm surprised you were able to get it working by making a config directory. This shouldn't have anything to do with the config directory as far as I can tell, since it looks to be file dictionaries and not the user dictionary that have the problem.

The issue appears to be with url.to_file_path().ok()? in harper-ls/src/backend.rs

for seg in url.to_file_path().ok()?.components() {

So maybe an invalid url is introduced to the doc_state map somewhere? I just don't know why this would only manifest itself on mac.

The documentation for .to_file_path() says:

Returns Err if the host is neither empty nor "localhost" (except on Windows, where file: URLs may have a non-local host), or if Path::new_opt() returns None. (That is, if the percent-decoded path contains a NUL byte or, for a Windows path, is not UTF-8.)

@zoidyzoidzoid
Copy link

I'm surprised you were able to get it working by making a config directory. This shouldn't have anything to do with the config directory as far as I can tell, since it looks to be file dictionaries and not the user dictionary that have the problem.

You're right, I thought I had stopped it from crashing, but I later realised I hadn't been testing it properly and it was still hanging and crashing for me!

@mrfragger
Copy link

yea I get same error on Mac OS 14.5 with VSCode harper plugin 13.0

[Info - 10:53:07 PM] Server initialized!
thread 'main' panicked at harper-ls/src/backend.rs:404:14:
called Result::unwrap() on an Err value: Unable to compute dictionary path.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
[Error - 10:59:45 PM] Client Harper: connection to server is erroring.
write EPIPE
Shutting down server.
[Error - 10:59:45 PM] Sending pending changes failed
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:95:16)
[Error - 10:59:45 PM] Delivering pending changes failed
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:95:16)
[Error - 10:59:45 PM] Delivering pending changes failed
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:95:16)
[Error - 10:59:45 PM] Server process exited with code 101.
[Error - 10:59:45 PM] Client Harper: connection to server is erroring.
Cannot call write after a stream was destroyed
[Error - 10:59:45 PM] Stopping server failed
Message: Cannot call write after a stream was destroyed
Code: -32099

@zoidyzoidzoid
Copy link

@mrfragger can you test if the following commands help?

mkdir -p "$HOME/Library/Application Support/harper-ls/"
mkdir -p "$HOME/Library/Application Support/harper-ls/file_dictionaries"

I tried enabling RUST_BACKTRACE and adding some debug statements to a custom harper-ls version, but it does seem to be working for me now. 🤔

@elijah-potter elijah-potter added the good first issue Good for newcomers label Jan 3, 2025
@elijah-potter
Copy link
Collaborator

I've gone ahead and improved the error handling here. This should no longer be an issue in the next release. Hopefully we can find out what buffer opens on MacOS that triggers it.

Once the release it out, I'll ping you here so we can confirm the fix is working.

@zoidyzoidzoid
Copy link

@elijah-potter Thanks!

@mrfragger
Copy link

mrfragger commented Jan 4, 2025

@mrfragger can you test if the following commands help?

mkdir -p "$HOME/Library/Application Support/harper-ls/"
mkdir -p "$HOME/Library/Application Support/harper-ls/file_dictionaries"

I tried enabling RUST_BACKTRACE and adding some debug statements to a custom harper-ls version, but it does seem to be working for me now. 🤔

yea I checked and those directories already exist. BTW, I should've said harper did work for 5 or 10 mins and I started adding about 10 words to the global dictionary. I decided I wanted to start keeping track of which ones I was adding. As soon as I created a new file in VSCode that's when harper crashed. No matter what I did disabled extension and restart extensions. Then re-enable. Uninstalled and then re-installed. Looking forward to new release to see if that fixes it or not.

ok : 3 hours later....it's working fine now and I can't get it to crash. Ultimately what made it work for me again was deleting dictionary.txt (the global dictionary file). Sidenote: It doesn't do 4.2MB (80 hours of transcription) markdown files that well. I'd suggest sticking to under 200KB is probably best.

edit: ok finally got it to crash again
thread 'main' panicked at harper-ls/src/backend.rs:404:14:
called Result::unwrap() on an Err value: Unable to compute dictionary path.
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
[Error - 9:14:31 PM] Server process exited with code 101.
[Error - 9:14:31 PM] The Harper server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

this happened when I switch to a plain text new document and pasted a word in VSCode

@elijah-potter
Copy link
Collaborator

I've just ran a release with the fixes. Would you mind checking if this problem persists with harper-ls v0.15.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers harper-ls
Projects
None yet
Development

No branches or pull requests

5 participants