1use std::sync::Arc;
3
4use miette::Diagnostic;
5use thiserror::Error;
6
7#[derive(Error, Diagnostic, Debug)]
8#[error("An error occurred while parsing testcases")]
9pub struct TestParseError {
11 #[related]
12 pub(crate) errors: Vec<TestErrorCase>,
13
14 #[source_code]
15 pub(crate) source_code: Option<miette::NamedSource<Arc<str>>>,
16}
17
18impl From<kdl::KdlError> for TestParseError {
19 fn from(source: kdl::KdlError) -> Self {
20 TestParseError {
21 errors: vec![TestErrorCase::Kdl { source }],
22 source_code: None,
23 }
24 }
25}
26
27impl From<TestErrorCase> for TestParseError {
28 fn from(source: TestErrorCase) -> Self {
29 TestParseError {
30 errors: vec![source],
31 source_code: None,
32 }
33 }
34}
35
36#[derive(Error, Diagnostic, Debug)]
37pub enum TestErrorCase {
39 #[error("An error occurred while parsing the KDL data")]
40 Kdl {
42 #[source]
43 source: kdl::KdlError,
45 },
46 #[error("Not a valid test case")]
47 #[diagnostic(help("The outer items must all be `testcase`s"))]
48 NotTestcase {
50 #[label("Expected a `testcase`")]
51 span: miette::SourceSpan,
53 },
54 #[error("An argument was missing")]
55 MissingArgument {
57 #[label("This node is missing an argument")]
58 parent: miette::SourceSpan,
60
61 #[help]
62 missing: String,
64 },
65 #[error("An argument was of the wrong type")]
66 WrongArgumentType {
68 #[label("This node has an argument of a wrong kind")]
69 parent: miette::SourceSpan,
71
72 #[label("this one")]
73 argument: miette::SourceSpan,
75
76 #[help]
77 expected: String,
79 },
80 #[error("Could not find condition with this name")]
81 UnknownCondition {
83 #[label]
84 condition: miette::SourceSpan,
86 },
87 #[error("Could not find verb with this name")]
88 UnknownVerb {
90 #[label]
91 verb: miette::SourceSpan,
93 },
94
95 #[error("A panic occurred while running the test")]
96 Panic {
98 #[diagnostic_source]
99 error: miette::Error,
101
102 #[label("in this node")]
103 label: miette::SourceSpan,
105 },
106
107 #[error("An error occurred while running the test")]
108 Error {
110 #[diagnostic_source]
111 error: miette::Error,
113
114 #[label("in this node")]
115 label: miette::SourceSpan,
117 },
118}