Skip to main content

webui_parser/
error.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3
4//! Error handling for the WebUI parser.
5
6use thiserror::Error;
7
8/// Result type for WebUI parser operations.
9pub type Result<T> = std::result::Result<T, ParserError>;
10
11/// Error type for WebUI parser.
12#[derive(Debug, Error)]
13pub enum ParserError {
14    /// Generic error.
15    #[error("Generic error: {0}")]
16    Generic(String),
17
18    /// I/O error with context.
19    #[error("I/O error: {context}: {source}")]
20    IO {
21        /// What operation failed.
22        context: String,
23        /// The underlying I/O error.
24        #[source]
25        source: std::io::Error,
26    },
27
28    /// Parse error.
29    #[error("Parse error: {0}")]
30    Parse(String),
31
32    /// Component error.
33    #[error("Component error: {0}")]
34    Component(String),
35
36    /// A component supplied its own `<template>` wrapper under
37    /// `CssStrategy::Module` but did not declare a
38    /// `shadowrootadoptedstylesheets` attribute. The framework cannot
39    /// silently inject the attribute without overriding developer intent
40    /// on the wrapper, so authoring help is surfaced at build time.
41    #[error(
42        "Component <{tag}> supplies its own <template> wrapper under --css=module but is \
43         missing the `shadowrootadoptedstylesheets` attribute, which is required to wire \
44         the component's CSS module into its shadow root. Add \
45         `shadowrootadoptedstylesheets=\"{tag}\"` to the <template> tag, or remove the \
46         <template> wrapper to let the framework manage it automatically."
47    )]
48    MissingAdoptedStylesheets {
49        /// The component tag name (e.g. `mp-app`).
50        tag: String,
51    },
52
53    /// CSS error.
54    #[error("CSS error: {0}")]
55    Css(String),
56
57    /// HTML error.
58    #[error("HTML error: {0}")]
59    Html(String),
60
61    /// Directive error.
62    #[error("Directive error: {0}")]
63    Directive(String),
64
65    /// Entity not found error.
66    #[error("Not found: {0}")]
67    NotFound(String),
68
69    /// TypeScript parse error.
70    #[error("TypeScript parse error: {0}")]
71    TsParseError(String),
72}