feat: graph-ir (continueing #6) #10

Merged
schrottkatze merged 37 commits from schrottkatze/iowo:graph-ir into main 2024-01-23 12:55:01 +00:00
2 changed files with 9 additions and 6 deletions
Showing only changes of commit de9ca81b65 - Show all commits

View file

@ -40,10 +40,13 @@ pub(super) fn find_config_file() -> Result<PathBuf, ConfigError> {
impl Configs {
pub fn read(p: PathBuf) -> Result<Self, ConfigError> {
match p.extension().map(|v| v.to_str().unwrap()) {
match p
.extension()
.map(|v| v.to_str().expect("config path to be UTF-8"))
{
Some("ron") => Ok(serde_json::from_str(&fs::read_to_string(p)?)?),
Some("json") => Ok(ron::from_str(&fs::read_to_string(p)?)?),
e => Err(ConfigError::UnknownExtension(e.map(|v| v.to_owned()))),
e => Err(ConfigError::UnknownExtension(e.map(str::to_string))),
}
}
}

View file

@ -3,12 +3,12 @@ use std::process;
use ron::error::Position;
/// Report an `Error` from the `serde_json` crate
pub fn report_serde_json_err(src: &str, err: serde_json::Error) -> ! {
pub fn report_serde_json_err(src: &str, err: &serde_json::Error) -> ! {
report_serde_err(src, err.line(), err.column(), err.to_string())
}
/// Report a `SpannedError` from the `ron` crate
pub fn report_serde_ron_err(src: &str, err: ron::error::SpannedError) -> ! {
pub fn report_serde_ron_err(src: &str, err: &ron::error::SpannedError) -> ! {
let Position { line, col } = err.position;
report_serde_err(src, line, col, err.to_string())
}
@ -23,8 +23,8 @@ fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! {
.with_message(msg)
.with_note("We'd like to give better errors, but serde errors are horrible to work with...")
.finish()
.print(("test", Source::from(src)))
.unwrap();
.eprint(("test", Source::from(src)))
.expect("writing error to stderr failed");
process::exit(1);
}