Handle ingested file prefix error

This commit is contained in:
Agus Zubiaga 2024-05-18 02:16:02 +02:00
parent 504107f90e
commit 46da864fea
No known key found for this signature in database

View file

@ -295,14 +295,21 @@ fn add_ingested_files<W: Write>(
Ok(defs) => RecursiveValueDefIter::new(&defs).try_for_each(|(def, _)| { Ok(defs) => RecursiveValueDefIter::new(&defs).try_for_each(|(def, _)| {
if let ValueDef::IngestedFileImport(IngestedFileImport { path, .. }) = def { if let ValueDef::IngestedFileImport(IngestedFileImport { path, .. }) = def {
if let StrLiteral::PlainLine(relative_path) = path.value { if let StrLiteral::PlainLine(relative_path) = path.value {
let mut abs_path: PathBuf = dot_roc_path.into(); let mut abs_path: PathBuf = relative_path.into();
abs_path.pop(); abs_path.pop();
abs_path.push(relative_path); abs_path.push(relative_path);
builder.append_path_with_name( match abs_path.strip_prefix(root_dir) {
abs_path.as_path(), Ok(name) => builder.append_path_with_name(abs_path.as_path(), name),
abs_path.strip_prefix(root_dir).unwrap(), Err(_) => {
) panic!(
"Cannot bundle {} (imported in {}) since it's outside {}",
abs_path.display(),
dot_roc_path.display(),
root_dir.display()
);
}
}
} else { } else {
unreachable!() unreachable!()
} }