Skip to content

Thread through the original error when opening archives #43389

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

Merged
merged 1 commit into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc_llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
};

Expand Down
7 changes: 3 additions & 4 deletions src/librustc_trans/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_trans/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ 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()
.filter_map(|s| s.ok())
.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())
}
Expand Down