1use crate::error::extension::LoadExtensionManifestError;
2use crate::error::fs::{
3 CanonicalizePathError, CreateDirAllError, EnsureDirExistsError, NoParentPathError,
4};
5use crate::error::get_user_home::GetUserHomeError;
6use crate::error::structured_file::StructuredFileError;
7use handlebars::RenderError;
8use std::path::PathBuf;
9use thiserror::Error;
10
11#[derive(Error, Debug)]
12pub enum ConfigError {
13 #[error("failed to ensure config directory exists")]
14 EnsureConfigDirectoryExistsFailed(#[source] EnsureDirExistsError),
15
16 #[error("Failed to determine config directory path")]
17 DetermineConfigDirectoryFailed(#[source] GetUserHomeError),
18}
19
20#[derive(Error, Debug)]
21pub enum GetOutputEnvFileError {
22 #[error("failed to canonicalize output_env_file")]
23 CanonicalizePath(#[from] CanonicalizePathError),
24
25 #[error("The output_env_file must be within the project root, but is {}", .0.display())]
26 OutputEnvFileMustBeInProjectRoot(PathBuf),
27
28 #[error("The output_env_file must be a relative path, but is {}", .0.display())]
29 OutputEnvFileMustBeRelative(PathBuf),
30
31 #[error(transparent)]
32 NoParentPath(#[from] NoParentPathError),
33}
34
35#[derive(Error, Debug)]
36pub enum GetTempPathError {
37 #[error(transparent)]
38 CreateDirAll(#[from] CreateDirAllError),
39}
40
41#[derive(Error, Debug)]
42#[error("failed to render field '{field}' with value '{value}'")]
43pub struct RenderErrorWithContext {
44 pub field: String,
45 pub value: String,
46 pub source: RenderError,
47}
48
49#[derive(Error, Debug)]
50#[error("failed to apply extension canister type '{extension}' to canister '{canister}'")]
51pub struct ApplyExtensionCanisterTypeErrorWithContext {
52 pub canister: Box<String>,
53 pub extension: Box<String>,
54 pub source: ApplyExtensionCanisterTypeError,
55}
56
57#[derive(Error, Debug)]
58pub enum ApplyExtensionCanisterTypesError {
59 #[error("the canisters field in dfx.json must be an object")]
60 CanistersFieldIsNotAnObject(),
61
62 #[error("canister '{0}' in dfx.json must be an object")]
63 CanisterIsNotAnObject(String),
64
65 #[error(transparent)]
66 ApplyExtensionCanisterType(#[from] ApplyExtensionCanisterTypeError),
67}
68
69#[derive(Error, Debug)]
70pub enum ApplyExtensionCanisterTypeError {
71 #[error("failed to apply defaults from extension '{extension}' to canister '{canister}'")]
72 ApplyDefaults {
73 canister: Box<String>,
74 extension: Box<String>,
75 source: ApplyExtensionCanisterTypeDefaultsError,
76 },
77
78 #[error(
79 "canister '{canister}' has unknown type '{extension}' and there is no installed extension by that name which could define it"
80 )]
81 NoExtensionForUnknownCanisterType { canister: String, extension: String },
82
83 #[error(transparent)]
84 LoadExtensionManifest(LoadExtensionManifestError),
85
86 #[error(
87 "canister '{canister}' has type '{extension}', but that extension does not define a canister type"
88 )]
89 ExtensionDoesNotDefineCanisterType { canister: String, extension: String },
90}
91
92#[derive(Error, Debug)]
93pub enum ApplyExtensionCanisterTypeDefaultsError {
94 #[error(transparent)]
95 AppendMetadata(#[from] AppendMetadataError),
96
97 #[error(transparent)]
98 MergeTechStackError(#[from] MergeTechStackError),
99
100 #[error(transparent)]
101 Render(Box<RenderErrorWithContext>),
102}
103
104#[derive(Error, Debug)]
105pub enum AppendMetadataError {
106 #[error("expected canister metadata to be an array")]
107 ExpectedCanisterMetadataArray,
108
109 #[error("expected extension canister type metadata to be an array")]
110 ExpectedExtensionCanisterTypeMetadataArray,
111}
112
113#[derive(Error, Debug)]
114pub enum MergeTechStackError {
115 #[error("expected canister tech_stack to be an object")]
116 ExpectedCanisterTechStackObject,
117
118 #[error("expected extension canister type tech_stack to be an object")]
119 ExpectedExtensionCanisterTypeTechStackObject,
120}
121
122#[derive(Error, Debug)]
123pub enum GetSharedWalletConfigPathError {
124 #[error(transparent)]
125 GetUserHome(#[from] GetUserHomeError),
126
127 #[error(transparent)]
128 StructuredFileError(#[from] StructuredFileError),
129}