Thread through the original error when opening archives

This updates the management of opening archives to thread through the original
piece of error information from LLVM over to the end consumer, trans.
This commit is contained in:
Alex Crichton 2017-07-21 09:41:20 -07:00
parent 9d54ebe550
commit 81eea9e431
3 changed files with 14 additions and 15 deletions

View File

@ -39,14 +39,14 @@ impl ArchiveRO {
///
/// If this archive is used with a mutable method, then an error will be
/// raised.
pub fn open(dst: &Path) -> Option<ArchiveRO> {
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
return unsafe {
let s = path2cstr(dst);
let ar = ::LLVMRustOpenArchive(s.as_ptr());
if ar.is_null() {
None
Err(::last_error().unwrap_or("failed to open archive".to_string()))
} else {
Some(ArchiveRO { ptr: ar })
Ok(ArchiveRO { ptr: ar })
}
};

View File

@ -126,7 +126,7 @@ impl<'a> ArchiveBuilder<'a> {
Some(ref src) => src,
None => return None,
};
self.src_archive = Some(ArchiveRO::open(src));
self.src_archive = Some(ArchiveRO::open(src).ok());
self.src_archive.as_ref().unwrap().as_ref()
}
@ -186,9 +186,8 @@ impl<'a> ArchiveBuilder<'a> {
where F: FnMut(&str) -> bool + 'static
{
let archive = match ArchiveRO::open(archive) {
Some(ar) => ar,
None => return Err(io::Error::new(io::ErrorKind::Other,
"failed to open archive")),
Ok(ar) => ar,
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
};
self.additions.push(Addition::Archive {
archive: archive,

View File

@ -31,10 +31,10 @@ impl MetadataLoader for LlvmMetadataLoader {
// just keeping the archive along while the metadata is in use.
let archive = ArchiveRO::open(filename)
.map(|ar| OwningRef::new(box ar))
.ok_or_else(|| {
debug!("llvm didn't like `{}`", filename.display());
format!("failed to read rlib metadata: '{}'", filename.display())
})?;
.map_err(|e| {
debug!("llvm didn't like `{}`: {}", filename.display(), e);
format!("failed to read rlib metadata in '{}': {}", filename.display(), e)
})?;
let buf: OwningRef<_, [u8]> = archive
.try_map(|ar| {
ar.iter()
@ -42,10 +42,10 @@ impl MetadataLoader for LlvmMetadataLoader {
.find(|sect| sect.name() == Some(METADATA_FILENAME))
.map(|s| s.data())
.ok_or_else(|| {
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
format!("failed to read rlib metadata: '{}'",
filename.display())
})
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
format!("failed to read rlib metadata: '{}'",
filename.display())
})
})?;
Ok(buf.erase_owner())
}