From fb91deb8d9210ceb95b03f3d05d9713be064577d Mon Sep 17 00:00:00 2001 From: Firas al-Khalil Date: Fri, 26 Dec 2025 12:32:43 +0100 Subject: [PATCH] fix(cli): report library load failure Instead of panicking somehere else. This happens on concurrent builds of the the same grammar. (cherry picked from commit 5293dd683ed69899c5cf0a215e09a86d0d814adf) --- crates/loader/src/loader.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/loader/src/loader.rs b/crates/loader/src/loader.rs index d64b89de..310fe319 100644 --- a/crates/loader/src/loader.rs +++ b/crates/loader/src/loader.rs @@ -1089,6 +1089,26 @@ impl Loader { } } + // Ensure the dynamic library exists before trying to load it. This can + // happen in race conditions where we couldn't acquire the lock because + // another process was compiling but it still haven't finished by the + // time we reach this point, so the output file still doesn't exist. + // + // Instead of complaining about library load failure in `load_language`, + // inform the user about the precise issue. + if !output_path.exists() { + let msg = format!( + "Dynamic library `{}` not found after build attempt. \ + Are you running multiple processes building to the same output location?", + output_path.display() + ); + + return Err(LoaderError::IO(IoError::new( + std::io::Error::new(std::io::ErrorKind::NotFound, msg), + Some(output_path.as_path()), + ))); + } + Self::load_language(&output_path, &language_fn_name) }