app(doc): well... write the docs
This commit is contained in:
parent
6006f92d9c
commit
0615ea653c
5 changed files with 25 additions and 6 deletions
|
@ -2,16 +2,19 @@ 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) -> ! {
|
||||
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) -> ! {
|
||||
let Position { line, col } = err.position;
|
||||
report_serde_err(src, line, col, err.to_string())
|
||||
}
|
||||
|
||||
pub fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! {
|
||||
/// Basic function for reporting serde type of errors
|
||||
fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! {
|
||||
use ariadne::{Label, Report, Source};
|
||||
let offset = try_reconstruct_loc(src, line, col);
|
||||
|
||||
|
@ -24,6 +27,8 @@ pub fn report_serde_err(src: &str, line: usize, col: usize, msg: String) -> ! {
|
|||
.unwrap();
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
/// Reconstruct a byte offset from the line + column numbers typical from serde crates
|
||||
fn try_reconstruct_loc(src: &str, line_nr: usize, col_nr: usize) -> usize {
|
||||
let (line_nr, col_nr) = (line_nr - 1, col_nr - 1);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue