Skip to main content

mz_deploy/project/error/
load.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//! Load errors for project file I/O operations.
11//!
12//! This module defines errors that occur during project file loading,
13//! directory traversal, and file system operations.
14
15use std::path::PathBuf;
16use thiserror::Error;
17
18/// Errors that occur during project file loading and I/O operations.
19#[derive(Debug, Error)]
20pub enum LoadError {
21    #[error(transparent)]
22    BuildArtifactFailed(#[from] crate::project::compiler::cache::CacheError),
23
24    /// Project root directory does not exist
25    #[error("Project root directory does not exist: {path}")]
26    RootNotFound {
27        /// The path that was not found
28        path: PathBuf,
29    },
30
31    /// Project root path is not a directory
32    #[error("Project root is not a directory: {path}")]
33    RootNotDirectory {
34        /// The path that is not a directory
35        path: PathBuf,
36    },
37
38    /// models/ subdirectory does not exist
39    #[error("models/ directory not found in project root: {path}")]
40    ModelsNotFound {
41        /// The expected models/ path
42        path: PathBuf,
43    },
44
45    /// Failed to read a directory
46    #[error("Failed to read directory: {path}")]
47    DirectoryReadFailed {
48        /// The directory that couldn't be read
49        path: PathBuf,
50        /// The underlying I/O error
51        #[source]
52        source: std::io::Error,
53    },
54
55    /// Failed to read a directory entry
56    #[error("Failed to read directory entry in: {directory}")]
57    EntryReadFailed {
58        /// The directory containing the entry
59        directory: PathBuf,
60        /// The underlying I/O error
61        #[source]
62        source: std::io::Error,
63    },
64
65    /// Failed to read a SQL file
66    #[error("Failed to read SQL file: {path}")]
67    FileReadFailed {
68        /// The file that couldn't be read
69        path: PathBuf,
70        /// The underlying I/O error
71        #[source]
72        source: std::io::Error,
73    },
74
75    #[error("Failed to write cache file: {path}")]
76    CacheWriteFailed {
77        path: PathBuf,
78        #[source]
79        source: std::io::Error,
80    },
81
82    #[error("Failed to create directory: {path}")]
83    DirectoryCreationFailed {
84        path: PathBuf,
85        #[source]
86        source: std::io::Error,
87    },
88
89    /// Invalid file name (couldn't extract stem)
90    #[error("Invalid file name: {path}")]
91    InvalidFileName {
92        /// The file with the invalid name
93        path: PathBuf,
94    },
95
96    /// Failed to extract schema name from path
97    #[error("Failed to extract schema from path: {path}")]
98    SchemaExtractionFailed {
99        /// The path where extraction failed
100        path: PathBuf,
101    },
102
103    /// Failed to extract database name from path
104    #[error("Failed to extract database from path: {path}")]
105    DatabaseExtractionFailed {
106        /// The path where extraction failed
107        path: PathBuf,
108    },
109
110    /// Two files resolve to the same object name for the active profile
111    #[error(
112        "duplicate object '{name}' for profile '{profile}': both {path1} and {path2} resolve to the same name"
113    )]
114    DuplicateProfileObject {
115        name: String,
116        profile: String,
117        path1: PathBuf,
118        path2: PathBuf,
119    },
120}