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::VecSubscriptNonExisting => {
16 Report::build(Kind::Error, 104, "vector subscript failed", span)
17 }
18 RuntimeErrorKind::MapKeyNonExisting => {
19 Report::build(Kind::Error, 104, "map key does not exist", span)
20 }
21 RuntimeErrorKind::ExpectedInt => Report::build(Kind::Error, 104, "expected int", span),
22 RuntimeErrorKind::ExpectedString => {
23 Report::build(Kind::Error, 104, "expected string", span)
24 }
25 RuntimeErrorKind::ValueError(_) => todo!(),
26 RuntimeErrorKind::ArgumentIsNotMutable => {
27 Report::build(Kind::Error, 104, "argument is not mutable", span)
28 }
29 RuntimeErrorKind::ExpectedOptional => {
30 Report::build(Kind::Error, 104, "expected optional", span)
31 }
32 RuntimeErrorKind::NonUniqueKeysInMapLiteralDetected => todo!(),
33 RuntimeErrorKind::NotAnArray => todo!(),
34 RuntimeErrorKind::NotSparseValue => todo!(),
35 RuntimeErrorKind::CoerceOptionToBoolFailed => todo!(),
36 RuntimeErrorKind::VariableWasNotMutable => todo!(),
37 RuntimeErrorKind::ContinueNotAllowedHere => todo!(),
38 RuntimeErrorKind::BreakNotAllowedHere => todo!(),
39 RuntimeErrorKind::NotAMap => todo!(),
40 RuntimeErrorKind::NotAMap2 => todo!(),
41 RuntimeErrorKind::MissingExternalFunction(_) => todo!(),
42 RuntimeErrorKind::WrongNumberOfArguments(_, _) => todo!(),
43 RuntimeErrorKind::RangeItemMustBeInt => todo!(),
44 RuntimeErrorKind::OperationRequiresArray => todo!(),
45 RuntimeErrorKind::ExpectedFloat => todo!(),
46 RuntimeErrorKind::ExpectedTwoFloatTuple => todo!(),
47 RuntimeErrorKind::ExpectedFunction => todo!(),
48 RuntimeErrorKind::NotSparseId => todo!(),
49 RuntimeErrorKind::ReturnNotAllowedHere => todo!(),
50 RuntimeErrorKind::ExpectedStruct => {
51 Report::build(Kind::Error, 154, "expected struct", span)
52 }
53 RuntimeErrorKind::ExpectedArray => todo!(),
54 RuntimeErrorKind::ExpectedMap => todo!(),
55 RuntimeErrorKind::PostfixChainError => todo!(),
56 RuntimeErrorKind::IndexOutOfBounds => todo!(),
57 &RuntimeErrorKind::DivideByZero | &RuntimeErrorKind::MapKeyAlreadyExists => todo!(),
58 RuntimeErrorKind::MustHaveGuardArmThatMatches => todo!(),
59 RuntimeErrorKind::CouldNotConvertFromSignal => todo!(),
60 &RuntimeErrorKind::UnknownMutIntrinsic | &RuntimeErrorKind::UnknownGenericIntrinsic => {
61 todo!()
62 }
63 };
64
65 b.error_module = "R".to_string();
66 b
67}
68
69pub fn show_runtime_error(err: &RuntimeError, source_map: &SourceMap, current_path: &Path) {
71 let builder = build_runtime_error(err);
72 build_and_print(builder, source_map, current_path)
73}