Skip to content

Commit d04cd8f

Browse files
committed
fix: Expose errors where relevant in the API
The errors were only fixture related, so moved them there to better help people navigate the API. This is a part of #19.
1 parent 6c9876d commit d04cd8f

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/fixture.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use std::path;
66
use globwalk;
77
use tempfile;
88

9-
use errors;
10-
use errors::ResultChainExt;
11-
9+
pub use errors::*;
1210
pub use tempfile::TempDir;
1311

1412
/// Access paths within [`TempDir`] for testing.
@@ -196,14 +194,14 @@ pub trait PathCopy {
196194
/// temp.copy_from(".", &["*.rs"]).unwrap();
197195
/// temp.close().unwrap();
198196
/// ```
199-
fn copy_from<P, S>(&self, source: P, patterns: &[S]) -> Result<(), errors::FixtureError>
197+
fn copy_from<P, S>(&self, source: P, patterns: &[S]) -> Result<(), FixtureError>
200198
where
201199
P: AsRef<path::Path>,
202200
S: AsRef<str>;
203201
}
204202

205203
impl PathCopy for tempfile::TempDir {
206-
fn copy_from<P, S>(&self, source: P, patterns: &[S]) -> Result<(), errors::FixtureError>
204+
fn copy_from<P, S>(&self, source: P, patterns: &[S]) -> Result<(), FixtureError>
207205
where
208206
P: AsRef<path::Path>,
209207
S: AsRef<str>,
@@ -213,7 +211,7 @@ impl PathCopy for tempfile::TempDir {
213211
}
214212

215213
impl PathCopy for ChildPath {
216-
fn copy_from<P, S>(&self, source: P, patterns: &[S]) -> Result<(), errors::FixtureError>
214+
fn copy_from<P, S>(&self, source: P, patterns: &[S]) -> Result<(), FixtureError>
217215
where
218216
P: AsRef<path::Path>,
219217
S: AsRef<str>,
@@ -241,34 +239,34 @@ fn copy_files<S>(
241239
target: &path::Path,
242240
source: &path::Path,
243241
patterns: &[S],
244-
) -> Result<(), errors::FixtureError>
242+
) -> Result<(), FixtureError>
245243
where
246244
S: AsRef<str>,
247245
{
248246
// `walkdir`, on Windows, seems to convert "." into "" which then fails.
249247
let source = source
250248
.canonicalize()
251-
.chain(errors::FixtureError::new(errors::FixtureKind::Walk))?;
249+
.chain(FixtureError::new(FixtureKind::Walk))?;
252250
for entry in globwalk::GlobWalkerBuilder::from_patterns(&source, patterns)
253251
.follow_links(true)
254252
.build()
255-
.chain(errors::FixtureError::new(errors::FixtureKind::Walk))?
253+
.chain(FixtureError::new(FixtureKind::Walk))?
256254
{
257255
println!("{:?}", entry);
258-
let entry = entry.chain(errors::FixtureError::new(errors::FixtureKind::Walk))?;
256+
let entry = entry.chain(FixtureError::new(FixtureKind::Walk))?;
259257
let rel = entry
260258
.path()
261259
.strip_prefix(&source)
262260
.expect("entries to be under `source`");
263261
let target_path = target.join(rel);
264262
if entry.file_type().is_dir() {
265263
fs::create_dir_all(target_path)
266-
.chain(errors::FixtureError::new(errors::FixtureKind::CreateDir))?;
264+
.chain(FixtureError::new(FixtureKind::CreateDir))?;
267265
} else if entry.file_type().is_file() {
268266
fs::create_dir_all(target_path.parent().expect("at least `target` exists"))
269-
.chain(errors::FixtureError::new(errors::FixtureKind::CreateDir))?;
267+
.chain(FixtureError::new(FixtureKind::CreateDir))?;
270268
fs::copy(entry.path(), target_path)
271-
.chain(errors::FixtureError::new(errors::FixtureKind::CopyFile))?;
269+
.chain(FixtureError::new(FixtureKind::CopyFile))?;
272270
}
273271
}
274272
Ok(())

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern crate tempfile;
4848

4949
pub mod assert;
5050
pub mod fixture;
51-
pub mod errors;
51+
mod errors;
5252

5353
// Pulling this in for convenience-sake
5454
#[doc(inline)]

0 commit comments

Comments
 (0)