mz_deploy/project/error.rs
1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Error types for Materialize project operations.
11//!
12//! This module provides structured error types using `thiserror` that capture rich
13//! contextual information about failures during project loading, parsing, and validation.
14//!
15//! # Error Hierarchy
16//!
17//! ```text
18//! ProjectError
19//! ├── Load(LoadError) - File I/O and directory traversal errors
20//! ├── Parse(ParseError) - SQL parsing errors
21//! ├── Validation(ValidationError) - Semantic validation errors with context
22//! └── Dependency(DependencyError) - Dependency graph analysis errors
23//! ```
24//!
25//! # Error Context
26//!
27//! Validation errors are wrapped with `ErrorContext` that captures:
28//! - File path where the error occurred
29//! - SQL statement that caused the error (when available)
30//!
31//! This design avoids duplicating context fields across all error variants.
32
33mod dependency;
34mod load;
35mod parse;
36pub(crate) mod validation;
37
38pub(crate) use dependency::DependencyError;
39pub(crate) use load::LoadError;
40pub(crate) use parse::ParseError;
41pub(crate) use validation::{ValidationError, ValidationErrorKind, ValidationErrors};
42
43use thiserror::Error;
44
45/// Top-level error type for all project operations.
46///
47/// This is the main error type returned by project loading and validation functions.
48/// It wraps more specific error types that provide detailed context.
49#[derive(Debug, Error)]
50pub enum ProjectError {
51 /// Error occurred while loading project files from disk
52 #[error(transparent)]
53 Load(#[from] LoadError),
54
55 /// Error occurred while parsing SQL statements
56 #[error(transparent)]
57 Parse(#[from] ParseError),
58
59 /// Error occurred during semantic validation (may contain multiple errors)
60 #[error(transparent)]
61 Validation(#[from] ValidationErrors),
62
63 /// Error occurred during dependency analysis
64 #[error(transparent)]
65 Dependency(#[from] DependencyError),
66}