vrl/diagnostic/
mod.rs

1#![deny(
2    warnings,
3    clippy::all,
4    clippy::pedantic,
5    unreachable_pub,
6    unused_allocation,
7    unused_extern_crates,
8    unused_assignments,
9    unused_comparisons
10)]
11#![allow(
12clippy::match_bool, // allowed in initial deny commit
13clippy::missing_errors_doc, // allowed in initial deny commit
14clippy::module_name_repetitions, // allowed in initial deny commit
15clippy::semicolon_if_nothing_returned,  // allowed in initial deny commit
16clippy::needless_pass_by_value,  // allowed in initial deny commit
17)]
18
19pub use diagnostic::{Diagnostic, DiagnosticList};
20pub use formatter::Formatter;
21pub use label::Label;
22pub use note::Note;
23pub use severity::Severity;
24pub use span::{Span, span};
25
26#[allow(clippy::module_inception)]
27mod diagnostic;
28mod formatter;
29mod label;
30mod note;
31mod severity;
32mod span;
33
34const VRL_DOCS_ROOT_URL: &str = "https://vrl.dev";
35const VRL_ERROR_DOCS_ROOT_URL: &str = "https://errors.vrl.dev";
36const VRL_FUNCS_ROOT_URL: &str = "https://functions.vrl.dev";
37
38/// A trait that can be implemented by error types to provide diagnostic
39/// information about the given error.
40pub trait DiagnosticMessage: std::error::Error {
41    fn code(&self) -> usize;
42
43    /// The subject message of the error.
44    ///
45    /// Defaults to the error message itself.
46    fn message(&self) -> String {
47        self.to_string()
48    }
49
50    /// One or more labels to provide more context for a given error.
51    ///
52    /// Defaults to no labels.
53    fn labels(&self) -> Vec<Label> {
54        vec![]
55    }
56
57    /// One or more notes shown at the bottom of the diagnostic message.
58    ///
59    /// Defaults to no notes.
60    fn notes(&self) -> Vec<Note> {
61        vec![]
62    }
63
64    /// The severity of the message.
65    ///
66    /// Defaults to `error`.
67    fn severity(&self) -> Severity {
68        Severity::Error
69    }
70}
71
72pub struct Urls;
73
74impl Urls {
75    fn vrl_root_url() -> String {
76        VRL_DOCS_ROOT_URL.into()
77    }
78
79    #[must_use]
80    pub fn func_docs(ident: &str) -> String {
81        format!("{VRL_FUNCS_ROOT_URL}/{ident}")
82    }
83
84    fn error_handling_url() -> String {
85        format!("{VRL_ERROR_DOCS_ROOT_URL}/#handling")
86    }
87
88    fn error_code_url(code: usize) -> String {
89        format!("{VRL_ERROR_DOCS_ROOT_URL}/{code}")
90    }
91
92    #[must_use]
93    pub fn expression_docs_url(expr: &str) -> String {
94        format!("{VRL_DOCS_ROOT_URL}/expressions/{expr}")
95    }
96
97    fn example_docs() -> String {
98        format!("{VRL_DOCS_ROOT_URL}/examples")
99    }
100
101    #[must_use]
102    pub fn func_characteristics() -> String {
103        format!("{VRL_DOCS_ROOT_URL}/expressions/#function-call-characteristics")
104    }
105}