Skip to content

Commit de25a30

Browse files
bors[bot]burrbull
andauthored
Merge #117
117: improve yaml path errors r=adamgreig a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 6285a7a + 539f169 commit de25a30

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/convert/convert_cli.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::{Read, Write};
33
use std::str::FromStr;
44
use std::{fs::File, path::Path};
55

6-
#[derive(Clone, Copy, Debug, PartialEq)]
6+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
77
#[non_exhaustive]
88
pub enum InputFormat {
99
Xml,
@@ -23,7 +23,7 @@ impl FromStr for InputFormat {
2323
}
2424
}
2525

26-
#[derive(Clone, Copy, Debug, PartialEq)]
26+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2727
#[non_exhaustive]
2828
pub enum OutputFormat {
2929
Xml,

src/interrupts/svd_reader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ struct PeripheralXml {
1919
interrupt: Option<Vec<Interrupt>>,
2020
}
2121

22-
#[derive(Deserialize, Debug, PartialEq)]
22+
#[derive(Deserialize, Debug, PartialEq, Eq)]
2323
pub struct Interrupt {
2424
pub name: String,
2525
pub description: Option<String>,
2626
pub value: u32,
2727
}
2828

29-
#[derive(Debug, PartialEq)]
29+
#[derive(Debug, PartialEq, Eq)]
3030
pub struct Peripheral {
3131
pub name: String,
3232
pub interrupt: Vec<Interrupt>,

src/patch/device.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl DeviceExt for Device {
202202
.collect::<Vec<_>>();
203203
let mut new = match pcopysrc.as_slice() {
204204
[ppath, pcopyname] => {
205-
let f = File::open(abspath(path, Path::new(ppath))).unwrap();
205+
let f = File::open(abspath(path, Path::new(ppath))?)?;
206206
let mut contents = String::new();
207207
(&f).read_to_string(&mut contents).unwrap();
208208
let filedev = svd_parser::parse(&contents)

src/patch/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn process_file(yaml_file: &Path) -> Result<()> {
4242
root.get_str("_svd")?
4343
.ok_or_else(|| anyhow!("You must have an svd key in the root YAML file"))?,
4444
),
45-
);
45+
)?;
4646
let mut svdpath_out = svdpath.clone();
4747
svdpath_out.set_extension("svd.patched");
4848
let f = File::open(svdpath)?;
@@ -69,8 +69,8 @@ pub fn process_file(yaml_file: &Path) -> Result<()> {
6969
}
7070

7171
/// Gets the absolute path of relpath from the point of view of frompath.
72-
fn abspath(frompath: &Path, relpath: &Path) -> PathBuf {
73-
std::fs::canonicalize(frompath.parent().unwrap().join(relpath)).unwrap()
72+
fn abspath(frompath: &Path, relpath: &Path) -> Result<PathBuf, std::io::Error> {
73+
std::fs::canonicalize(frompath.parent().unwrap().join(relpath))
7474
}
7575

7676
/// Recursively loads any included YAML files.
@@ -80,7 +80,9 @@ pub fn yaml_includes(parent: &mut Hash) -> Result<Vec<PathBuf>> {
8080
let self_path = PathBuf::from(parent.get(&y_path).unwrap().str()?);
8181
let inc = parent.get_vec("_include")?.unwrap_or(&Vec::new()).clone();
8282
for relpath in inc {
83-
let path = abspath(&self_path, Path::new(relpath.as_str().unwrap()));
83+
let relpath = relpath.as_str().unwrap();
84+
let path = abspath(&self_path, Path::new(relpath))
85+
.with_context(|| anyhow!("Opening file \"{}\" from file {:?}", relpath, self_path))?;
8486
if included.contains(&path) {
8587
continue;
8688
}

0 commit comments

Comments
 (0)