Skip to content
Open
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
12 changes: 10 additions & 2 deletions crates/apt-convert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use thiserror::Error;
pub enum Error {
#[error("apt error: {0}")]
Apt(#[from] apt::Error),
#[error("loading APT movie {}: {source}", base.display())]
LoadMovie { base: PathBuf, source: apt::Error },
#[error("apt-aux error: {0}")]
Aux(String),
#[error("swf read error: {0}")]
Expand Down Expand Up @@ -92,7 +94,10 @@ pub struct ConvertedMovie {
/// those too.
pub fn convert_movie(base: &Path, options: &ConvertOptions) -> Result<Vec<u8>> {
let base = apt::base_path(base);
let file = apt::AptFile::load(&base)?;
let file = apt::AptFile::load(&base).map_err(|source| Error::LoadMovie {
base: base.clone(),
source,
})?;
convert_loaded_movie(&base, &file, options)
}

Expand Down Expand Up @@ -135,7 +140,10 @@ pub fn convert_movie_with_imports(
Some(n) if seen.insert(n.to_string()) => n.to_string(),
_ => continue, // unnamed, or already converted
};
let file = apt::AptFile::load(&base)?;
let file = apt::AptFile::load(&base).map_err(|source| Error::LoadMovie {
base: base.clone(),
source,
})?;
if !options.inline_imports {
for import in &file.movie.imports {
if !seen.contains(&import.movie) {
Expand Down
14 changes: 14 additions & 0 deletions crates/apt/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use std::path::PathBuf;

use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("io error: {0}")]
Io(#[from] std::io::Error),

#[error("reading {}: {source}", path.display())]
ReadFile {
path: PathBuf,
source: std::io::Error,
},

#[error("parsing APT movie {}: {source}", base.display())]
Parse {
base: PathBuf,
source: Box<Error>,
},

#[error("not an APT file: bad header tag")]
BadAptTag,

Expand Down
17 changes: 14 additions & 3 deletions crates/apt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ impl AptFile {
/// Load from `<base>.apt` + `<base>.const`. `path` may be either file or the base name.
pub fn load(path: &Path) -> Result<AptFile> {
let base = base_path(path);
let apt_data = std::fs::read(base.with_extension("apt"))?;
let const_data = std::fs::read(base.with_extension("const"))?;
Self::read(&apt_data, &const_data)
let apt_path = base.with_extension("apt");
let const_path = base.with_extension("const");
let apt_data = std::fs::read(&apt_path).map_err(|source| Error::ReadFile {
path: apt_path,
source,
})?;
let const_data = std::fs::read(&const_path).map_err(|source| Error::ReadFile {
path: const_path,
source,
})?;
Self::read(&apt_data, &const_data).map_err(|source| Error::Parse {
base,
source: Box::new(source),
})
}
}

Expand Down
Loading