app(doc): well... write the docs

This commit is contained in:
Schrottkatze 2024-01-19 09:51:48 +01:00
parent 6006f92d9c
commit 0615ea653c
Signed by: schrottkatze
GPG key ID: DFD0FD205943C14A
5 changed files with 25 additions and 6 deletions

View file

@ -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);