1
1
use crate :: host:: HostParseError ;
2
2
use std:: { convert:: Infallible , num:: ParseIntError } ;
3
3
4
+ use super :: ParamSource ;
5
+
4
6
#[ derive( Debug , Clone , PartialEq , Eq , derive_more:: Display , PartialOrd , Ord ) ]
5
7
pub enum CompoundSource {
6
8
Dsn ,
@@ -46,22 +48,14 @@ pub enum InvalidDsnError {
46
48
BranchAndDatabase ,
47
49
}
48
50
49
- #[ derive( Debug , Clone , PartialEq , Eq , derive_more:: Display , PartialOrd , Ord ) ]
50
- pub enum EnvironmentSource {
51
- #[ display( "Explicit" ) ]
52
- Explicit ,
53
- #[ display( "Param::Env" ) ]
54
- Param ,
55
- }
56
-
57
51
#[ derive( Debug , derive_more:: Error , derive_more:: Display , PartialEq , Eq , PartialOrd , Ord ) ]
58
52
pub enum ParseError {
59
53
#[ display( "Credentials file not found" ) ]
60
54
CredentialsFileNotFound ,
61
- #[ display( "Environment variable not found : {_1} ({_0})" ) ]
62
- EnvNotFound ( EnvironmentSource , #[ error( not( source) ) ] String ) ,
63
- #[ display( "Exclusive options " ) ]
64
- ExclusiveOptions ,
55
+ #[ display( "Environment variable was not set : {_1} (from {_0})" ) ]
56
+ EnvNotFound ( ParamSource , #[ error( not( source) ) ] String ) ,
57
+ #[ display( "{_0} and {_1} are mutually exclusive and cannot be used together " ) ]
58
+ ExclusiveOptions ( String , String ) ,
65
59
#[ display( "File not found" ) ]
66
60
FileNotFound ,
67
61
#[ display( "Invalid credentials file: {_0}" ) ]
@@ -94,7 +88,7 @@ pub enum ParseError {
94
88
MultipleCompoundOpts ( #[ error( not( source) ) ] Vec < CompoundSource > ) ,
95
89
#[ display( "No options or .toml file" ) ]
96
90
NoOptionsOrToml ,
97
- #[ display( "Project not initialised " ) ]
91
+ #[ display( "Project not initialized " ) ]
98
92
ProjectNotInitialised ,
99
93
#[ display( "Secret key not found" ) ]
100
94
SecretKeyNotFound ,
@@ -107,7 +101,7 @@ impl ParseError {
107
101
match self {
108
102
Self :: EnvNotFound ( ..) => "env_not_found" ,
109
103
Self :: CredentialsFileNotFound => "credentials_file_not_found" ,
110
- Self :: ExclusiveOptions => "exclusive_options" ,
104
+ Self :: ExclusiveOptions ( .. ) => "exclusive_options" ,
111
105
Self :: FileNotFound => "file_not_found" ,
112
106
Self :: InvalidCredentialsFile ( _) => "invalid_credentials_file" ,
113
107
Self :: InvalidDatabase => "invalid_database" ,
@@ -136,7 +130,6 @@ impl ParseError {
136
130
match self {
137
131
Self :: EnvNotFound ( ..)
138
132
| Self :: CredentialsFileNotFound
139
- | Self :: ExclusiveOptions
140
133
| Self :: FileNotFound
141
134
| Self :: InvalidCredentialsFile ( _)
142
135
| Self :: InvalidDatabase
@@ -150,15 +143,24 @@ impl ParseError {
150
143
| Self :: InvalidUser
151
144
| Self :: InvalidCertificate
152
145
| Self :: InvalidDuration
153
- | Self :: MultipleCompoundEnv ( _)
154
- | Self :: MultipleCompoundOpts ( _)
155
- | Self :: NoOptionsOrToml
156
- | Self :: ProjectNotInitialised
157
146
| Self :: UnixSocketUnsupported => {
147
+ // The argument is invalid
148
+ gel_errors:: InvalidArgumentError :: with_source ( self )
149
+ }
150
+ Self :: MultipleCompoundEnv ( _)
151
+ | Self :: MultipleCompoundOpts ( _)
152
+ | Self :: ExclusiveOptions ( ..) => {
153
+ // The argument is valid, but the use is invalid
154
+ gel_errors:: InterfaceError :: with_source ( self )
155
+ }
156
+ Self :: NoOptionsOrToml | Self :: ProjectNotInitialised => {
157
+ // Credentials are missing
158
158
gel_errors:: ClientNoCredentialsError :: with_source ( self )
159
159
}
160
-
161
- Self :: SecretKeyNotFound => gel_errors:: NoCloudConfigFound :: with_source ( self ) ,
160
+ Self :: SecretKeyNotFound => {
161
+ // Required cloud configuration is missing
162
+ gel_errors:: NoCloudConfigFound :: with_source ( self )
163
+ }
162
164
}
163
165
}
164
166
}
0 commit comments