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

Panic when fetching grammars fail #2642

Closed
Frojdholm opened this issue Jun 1, 2022 · 0 comments · Fixed by #2641
Closed

Panic when fetching grammars fail #2642

Frojdholm opened this issue Jun 1, 2022 · 0 comments · Fixed by #2641
Labels
C-bug Category: This is a bug

Comments

@Frojdholm
Copy link
Contributor

Frojdholm commented Jun 1, 2022

Summary

When fetching/building grammars it's done in a thread pool where the results are communicated over a channel. On the first failure the receiver is closed and the error returned. This causes any sends that aren't completed yet to panic, spamming the terminal with jumbled error messages.

The panicing function is this (annotations mine)

fn run_parallel<F>(grammars: Vec<GrammarConfiguration>, job: F, action: &'static str) -> Result<()>
where
    F: Fn(GrammarConfiguration) -> Result<()> + std::marker::Send + 'static + Copy,
{
    let pool = threadpool::Builder::new().build();
    let (tx, rx) = channel();

    for grammar in grammars {
        let tx = tx.clone();

        pool.execute(move || {
            tx.send(job(grammar)).unwrap(); // <- this panics since rx is closed
        });
    }

    drop(tx);

    // TODO: print all failures instead of the first one found.
    rx.iter()
        .find(|result| result.is_err())
        .map(|err| err.with_context(|| format!("Failed to {} some grammar(s)", action)))
        .unwrap_or(Ok(())) // <- on the first error this returns, closing rx and causing any subsequent sends to fail
}

One solution could be to simply ignore the Results produced by tx.send (#2641). Another could be to use something like https://docs.rs/beau_collector/latest/beau_collector/ to collect all the errors into a single error that can be returned.

Reproduction Steps

$ mkdir runtime_test
$ sudo chown root:root runtime_test
$ HELIX_RUNTIME=$PWD/runtime_test hx -g fetch

Helix log

No response

Platform

Linux

Terminal Emulator

kitty

Helix Version

22.05-14-gfc666db6

@Frojdholm Frojdholm added the C-bug Category: This is a bug label Jun 1, 2022
@Frojdholm Frojdholm changed the title Terminal is spammed when fetching grammars fail Panic when fetching grammars fail Jun 1, 2022
@the-mikedavis the-mikedavis linked a pull request Jun 1, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant