ludus/src/errors.rs
2025-07-07 00:17:57 -04:00

116 lines
3.6 KiB
Rust

// use crate::process::{LErr, Trace};
use crate::validator::VErr;
use crate::value::Value;
use ariadne::{sources, Color, Label, Report, ReportKind};
use std::collections::HashSet;
<<<<<<< HEAD
// pub fn report_panic(err: LErr) {
// let mut srcs = HashSet::new();
// let mut stack = vec![];
// let mut order = 1;
// for entry in err.trace.iter().rev() {
// let Trace {
// callee,
// caller,
// function,
// arguments,
// input,
// src,
// } = entry;
// let (_, first_span) = callee;
// let (_, second_span) = caller;
// let Value::Fn(f) = function else {
// unreachable!()
// };
// let fn_name = f.borrow().name.clone();
// let i = first_span.start;
// let j = second_span.end;
// let label = Label::new((entry.input, i..j))
// .with_color(Color::Yellow)
// .with_message(format!("({order}) calling `{fn_name}` with `{arguments}`"));
// order += 1;
// stack.push(label);
// srcs.insert((*input, *src));
// }
||||||| things & stuff
pub fn report_panic(err: LErr) {
let mut srcs = HashSet::new();
let mut stack = vec![];
let mut order = 1;
for entry in err.trace.iter().rev() {
let Trace {
callee,
caller,
function,
arguments,
input,
src,
} = entry;
let (_, first_span) = callee;
let (_, second_span) = caller;
let Value::Fn(f) = function else {
unreachable!()
};
let fn_name = f.borrow().name.clone();
let i = first_span.start;
let j = second_span.end;
let label = Label::new((entry.input, i..j))
.with_color(Color::Yellow)
.with_message(format!("({order}) calling `{fn_name}` with `{arguments}`"));
order += 1;
stack.push(label);
srcs.insert((*input, *src));
}
=======
pub fn report_panic(err: LErr) {
let mut srcs = HashSet::new();
let mut stack = vec![];
let mut order = 1;
for entry in err.trace.iter().rev() {
let Trace {
callee,
caller,
function,
arguments,
input,
src,
} = entry;
let (_, first_span) = callee;
let (_, second_span) = caller;
let Value::Fn(f) = function else {
unreachable!()
};
let fn_name = f.name.clone();
let i = first_span.start;
let j = second_span.end;
let label = Label::new((entry.input, i..j))
.with_color(Color::Yellow)
.with_message(format!("({order}) calling `{fn_name}` with `{arguments}`"));
order += 1;
stack.push(label);
srcs.insert((*input, *src));
}
>>>>>>> main
// Report::build(ReportKind::Error, (err.input, err.span.into_range()))
// .with_message(format!("Ludus panicked! {}", err.msg))
// .with_label(Label::new((err.input, err.span.into_range())).with_color(Color::Red))
// .with_labels(stack)
// .with_note(err.extra)
// .finish()
// .print(sources(srcs.iter().copied()))
// .unwrap();
// }
pub fn report_invalidation(errs: Vec<VErr>) {
for err in errs {
Report::build(ReportKind::Error, (err.input, err.span.into_range()))
.with_message(err.msg.to_string())
.with_label(Label::new((err.input, err.span.into_range())).with_color(Color::Cyan))
.finish()
.print(sources(vec![(err.input, err.src)]))
.unwrap();
}
}