swamp_script_error_report/
runtime.rs1use crate::{Builder, Report, build_and_print};
2use eira::Kind;
3use std::path::Path;
4use swamp_script_eval::err::RuntimeErrorKind;
5use swamp_script_eval::prelude::RuntimeError;
6use swamp_script_source_map::SourceMap;
7
8#[must_use]
9pub fn build_runtime_error(err: &RuntimeError) -> Builder<usize> {
10 let span = &err.node.span;
11 let mut b = match &err.kind {
12 RuntimeErrorKind::StackCouldNotBePopped => {
13 Report::build(Kind::Error, 104, "stack could not pop", span)
14 }
15 RuntimeErrorKind::VecIndexOutOfBoundsError { tried, size } => {
16 Report::build(Kind::Error, 104, "index out of bounds", span)
17 .with_note(&format!("tried_index:{tried} size:{size}"))
18 }
19 RuntimeErrorKind::MapKeyNonExisting => {
20 Report::build(Kind::Error, 104, "map key does not exist", span)
21 }
22 RuntimeErrorKind::ExpectedInt => Report::build(Kind::Error, 104, "expected int", span),
23 RuntimeErrorKind::ExpectedString => {
24 Report::build(Kind::Error, 104, "expected string", span)
25 }
26 RuntimeErrorKind::ValueError(_) => todo!(),
27 RuntimeErrorKind::ArgumentIsNotMutable => {
28 Report::build(Kind::Error, 104, "argument is not mutable", span)
29 }
30 RuntimeErrorKind::ExpectedOptional => {
31 Report::build(Kind::Error, 104, "expected optional", span)
32 }
33 RuntimeErrorKind::NonUniqueKeysInMapLiteralDetected => todo!(),
34 RuntimeErrorKind::NotAnArray => todo!(),
35 RuntimeErrorKind::NotSparseValue => todo!(),
36 RuntimeErrorKind::CoerceOptionToBoolFailed => todo!(),
37 RuntimeErrorKind::VariableWasNotMutable => todo!(),
38 RuntimeErrorKind::ContinueNotAllowedHere => todo!(),
39 RuntimeErrorKind::BreakNotAllowedHere => todo!(),
40 RuntimeErrorKind::NotAMap => todo!(),
41 RuntimeErrorKind::NotAMap2 => todo!(),
42 RuntimeErrorKind::MissingExternalFunction(_) => todo!(),
43 RuntimeErrorKind::WrongNumberOfArguments(_, _) => todo!(),
44 RuntimeErrorKind::RangeItemMustBeInt => todo!(),
45 RuntimeErrorKind::OperationRequiresArray => todo!(),
46 RuntimeErrorKind::ExpectedFloat => todo!(),
47 RuntimeErrorKind::ExpectedTwoFloatTuple => todo!(),
48 RuntimeErrorKind::ExpectedFunction => todo!(),
49 RuntimeErrorKind::NotSparseId => todo!(),
50 RuntimeErrorKind::ReturnNotAllowedHere => todo!(),
51 RuntimeErrorKind::ExpectedStruct => {
52 Report::build(Kind::Error, 154, "expected struct", span)
53 }
54 RuntimeErrorKind::ExpectedArray => todo!(),
55 RuntimeErrorKind::ExpectedMap => todo!(),
56 RuntimeErrorKind::PostfixChainError => todo!(),
57 RuntimeErrorKind::IndexOutOfBounds => todo!(),
58 &RuntimeErrorKind::DivideByZero | &RuntimeErrorKind::MapKeyAlreadyExists => todo!(),
59 RuntimeErrorKind::MustHaveGuardArmThatMatches => todo!(),
60 RuntimeErrorKind::CouldNotConvertFromSignal => todo!(),
61 &RuntimeErrorKind::UnknownMutIntrinsic | &RuntimeErrorKind::UnknownGenericIntrinsic => {
62 todo!()
63 }
64 };
65
66 b.error_module = "R".to_string();
67 b
68}
69
70pub fn show_runtime_error(err: &RuntimeError, source_map: &SourceMap, current_path: &Path) {
72 let builder = build_runtime_error(err);
73 build_and_print(builder, source_map, current_path)
74}