grafbase_local_backend/
errors.rs

1pub use server::errors::ServerError;
2use std::{io, path::PathBuf};
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum BackendError {
7    /// returned if no port is available.
8    /// used specifically when searching for ports
9    #[error("could not find an available port")]
10    AvailablePort,
11
12    /// returned if a given port is in use and the search option is not used
13    #[error("port {0} is currently in use")]
14    PortInUse(u16),
15
16    /// wraps a server error
17    #[error(transparent)]
18    ServerError(ServerError),
19
20    /// returned when trying to initialize a project that conflicts with an existing project
21    #[error("{0} already exists")]
22    AlreadyAProject(PathBuf),
23
24    /// returned when trying to initialize a project that conflicts with an existing directory or file
25    #[error("{0} already exists")]
26    ProjectDirectoryExists(PathBuf),
27
28    /// returned if the current directory path could not be read
29    #[error("could not read the current path")]
30    ReadCurrentDirectory,
31
32    /// returned if the grafbase directory could not be created
33    #[error("could not create the 'grafbase' directory\ncaused by: {0}")]
34    CreateGrafbaseDirectory(io::Error),
35
36    /// returned if the project directory could not be created
37    #[error("could not create the project directory\ncaused by: {0}")]
38    CreateProjectDirectory(io::Error),
39
40    /// returned if a schema.graphql file could not be created
41    #[error("could not create a schema.graphql file\ncaused by: {0}")]
42    WriteSchema(io::Error),
43
44    /// returned if a .env file could not be created
45    #[error("could not create a .env file\ncaused by: {0}")]
46    WriteEnvFile(io::Error),
47
48    /// returned if .grafbase/database could not be deleted
49    #[error("could not delete '.grafbase/database'\ncaused by: {0}")]
50    DeleteDatabaseDirectory(io::Error),
51
52    /// returned if the grafbase directory for the project could not be deleted
53    #[error("could not delete the grafbase directory\ncaused by: {0}")]
54    DeleteGrafbaseDirectory(io::Error),
55
56    /// returned if a template URL is not supported
57    #[error("'{0}' is not a supported template URL")]
58    UnsupportedTemplateURL(String),
59
60    /// returned if a template URL could not be parsed
61    #[error("'{0}' is not a valid URL")]
62    MalformedTemplateURL(String),
63
64    /// returned if a repo tar could not be downloaded (on a non 200-299 status)
65    #[error("could not download the archive for '{0}'\ncaused by: {1}")]
66    StartDownloadRepoArchive(String, reqwest_middleware::Error),
67
68    /// returned if a repo tar could not be downloaded
69    #[error("could not download the archive for '{0}'")]
70    DownloadRepoArchive(String),
71
72    // since this is checked by looking for the extracted files on disk (extraction errors are checked beforehand),
73    // may have unlikely false positives if the files were deleted or moved by an external process immediately after extraction.
74    //
75    // TODO: consider adding an indicator that a file was extracted rather than checking on disk
76    // TODO: consider splitting this into internal and external template errors for clarity
77    // and change this error to something indicating that the extracted files were not found
78    /// returned if no files matching the template path were extracted (excluding extraction errors)
79    #[error("could not find the provided template within the template repository")]
80    TemplateNotFound,
81
82    /// returned if the extracted files from the template repository could not be moved
83    #[error("could not move the extracted files from the template repository\ncaused by: {0}")]
84    MoveExtractedFiles(io::Error),
85
86    /// returned if the entries of the template repository archive could not be read
87    #[error("could not read the entries of the template repository archive")]
88    ReadArchiveEntries,
89
90    /// returned if one of the entries of the template repository archive could not be extracted
91    #[error("could not extract an entry from the template repository archive\ncaused by: {0}")]
92    ExtractArchiveEntry(io::Error),
93
94    /// returned if the files extracted from the template repository archive could not be cleaned
95    #[error("could not clean the files extracted from the repository archive\ncaused by: {0}")]
96    CleanExtractedFiles(io::Error),
97
98    /// returned if the request to get the information for a repository could not be sent
99    #[error("could not get the repository information for {0}")]
100    StartGetRepositoryInformation(String),
101
102    /// returned if the request to get the information for a repository returned a non 200-299 status
103    #[error("could not get the repository information for {0}")]
104    GetRepositoryInformation(String),
105
106    /// returned if the request to get the information for a repository returned a response that could not be parsed
107    #[error("could not read the repository information for {0}")]
108    ReadRepositoryInformation(String),
109}