brisk_it/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! Convenient function to generate errors

/// Errors that are caused by bugs.
pub fn impossible(span: proc_macro2::Span) -> proc_macro2::TokenStream {
    return generic_error("Impossible error.", span);
}

/// Generic error.
pub fn generic_error<T: std::fmt::Display>(
    text: T,
    span: proc_macro2::Span,
) -> proc_macro2::TokenStream {
    return syn::Error::new(span, text).into_compile_error().into();
}

/// Errors used for unknown properties
pub fn unknown_property(prop: crate::component::PropertyValue) -> proc_macro2::TokenStream {
    return generic_error(format!("Unknown property {}", prop.name), prop.name.span());
}

/// Errors used for missing required properties
pub fn missing_property(component_name: &syn::Ident, prop_name: &str) -> proc_macro2::TokenStream {
    return generic_error(
        format!("Missing required property '{}'", prop_name),
        component_name.span(),
    );
}