@@ -2,6 +2,8 @@ use colored::*;
2
2
use std:: { path:: PathBuf , process:: exit} ;
3
3
use thiserror:: Error ;
4
4
5
+ use crate :: fmtln;
6
+
5
7
#[ derive( Error , Debug ) ]
6
8
pub enum SnmError {
7
9
#[ error( "Build config error: {0}" ) ]
@@ -25,9 +27,6 @@ pub enum SnmError {
25
27
#[ error( "Deserialize error: {0}" ) ]
26
28
DeserializeError ( #[ from] serde_json:: Error ) ,
27
29
28
- #[ error( "Not found: {0}" ) ]
29
- NotFoundResourceError ( String ) ,
30
-
31
30
#[ error( "Http status code not ok" ) ]
32
31
HttpStatusCodeUnOk ,
33
32
@@ -37,14 +36,11 @@ pub enum SnmError {
37
36
#[ error( "Get workspace dir error" ) ]
38
37
GetWorkspaceError ,
39
38
40
- #[ error( "Not found valid version" ) ]
41
- NotFoundValidNodeVersionDeclaration ,
42
-
43
39
#[ error( "No default node binary" ) ]
44
40
NoDefaultNodeBinary ,
45
41
46
- #[ error( "File already exists {0 }" ) ]
47
- FileAlreadyExists ( PathBuf ) ,
42
+ #[ error( "File already exists {file_path }" ) ]
43
+ FileAlreadyExists { file_path : PathBuf } ,
48
44
49
45
#[ error( "Exceeded maximum retry attempts: {0}" ) ]
50
46
ExceededMaxRetries ( String ) ,
@@ -97,7 +93,7 @@ pub fn create_error_message(message: String, descriptions: Vec<String>) -> Strin
97
93
. iter ( )
98
94
. map ( |value| format ! ( "{:<4}{}" , "" , value) )
99
95
. collect :: < Vec < String > > ( )
100
- . join ( "\r \n " . repeat ( 2 ) . as_str ( ) ) ;
96
+ . join ( "\r \n " . repeat ( 1 ) . as_str ( ) ) ;
101
97
102
98
format ! (
103
99
r##"
@@ -106,13 +102,26 @@ pub fn create_error_message(message: String, descriptions: Vec<String>) -> Strin
106
102
{:<3}{}
107
103
108
104
{}
109
- "##,
105
+ "## ,
110
106
"👹" , message, "📋" , "Explain" , description
111
107
)
112
108
}
113
109
114
110
pub fn friendly_error_message ( error : SnmError ) {
115
111
match error {
112
+ SnmError :: SNMBinaryProxyFail { stderr } => {
113
+ eprintln ! (
114
+ r##"
115
+ 👹 SNM proxy error info:
116
+
117
+ {}
118
+ "## ,
119
+ stderr
120
+ )
121
+ }
122
+ SnmError :: NoDefaultNodeBinary => {
123
+ eprintln ! ( r##"[error]: No default node binary"## ) ;
124
+ }
116
125
SnmError :: ParsePackageManagerError {
117
126
raw_package_manager,
118
127
} => {
@@ -135,23 +144,14 @@ pub fn friendly_error_message(error: SnmError) {
135
144
SnmError :: ExceededMaxRetries ( url) => {
136
145
let message = create_error_message (
137
146
"Exceeded max retries" . to_string ( ) ,
138
- vec ! [ format!(
139
- "The download failed after {} retries." ,
140
- url. to_string( ) . bold( ) . red( )
141
- ) ] ,
147
+ vec ! [
148
+ fmtln!( "URL {}" , url. to_string( ) . bold( ) . red( ) ) ,
149
+ fmtln!( "The download failed after 3 retries." , ) ,
150
+ fmtln!( "Please check the network connection and the download URL" , ) ,
151
+ ] ,
142
152
) ;
143
153
eprintln ! ( "{}" , message) ;
144
154
}
145
- SnmError :: NotFoundResourceError ( url) => {
146
- eprintln ! (
147
- r##"
148
- 👹 Not found resource
149
-
150
- The resource {} was not found.
151
- "## ,
152
- url. to_string( ) . bold( ) . red( )
153
- ) ;
154
- }
155
155
SnmError :: GetHomeDirError => {
156
156
eprintln ! (
157
157
r##"
@@ -181,22 +181,17 @@ pub fn friendly_error_message(error: SnmError) {
181
181
"##
182
182
) ;
183
183
}
184
- SnmError :: FileAlreadyExists ( path_buf) => {
185
- eprintln ! (
186
- r##"
187
- 👹 File already exists
188
-
189
- The file {} already exists.
190
- "## ,
191
- path_buf. to_string_lossy( ) . bold( ) . red( )
184
+ SnmError :: FileAlreadyExists { file_path } => {
185
+ let message = create_error_message (
186
+ "File already exists" . to_string ( ) ,
187
+ vec ! [ format!(
188
+ "The file {} already exists." ,
189
+ file_path. to_string_lossy( ) . bold( ) . red( )
190
+ ) ] ,
192
191
) ;
192
+ eprintln ! ( "{}" , message) ;
193
193
}
194
- SnmError :: NotFoundValidNodeVersionDeclaration => {
195
- eprintln ! ( r##"[error]: Not found valid node version declaration"## ) ;
196
- }
197
- SnmError :: NoDefaultNodeBinary => {
198
- eprintln ! ( r##"[error]: No default node binary"## ) ;
199
- }
194
+
200
195
SnmError :: NotFoundCommandError { bin_name } => {
201
196
let message = create_error_message (
202
197
format ! ( "Not found command {}" , bin_name. bold( ) . red( ) ) ,
@@ -222,16 +217,6 @@ pub fn friendly_error_message(error: SnmError) {
222
217
) ;
223
218
eprintln ! ( "{}" , message) ;
224
219
}
225
- SnmError :: SNMBinaryProxyFail { stderr } => {
226
- eprintln ! (
227
- r##"
228
- 👹 SNM proxy error info:
229
-
230
- {}
231
- "## ,
232
- stderr
233
- )
234
- }
235
220
SnmError :: ShasumError {
236
221
file_path,
237
222
expect,
@@ -272,7 +257,7 @@ pub fn friendly_error_message(error: SnmError) {
272
257
let message = create_error_message (
273
258
format ! ( "Unsupported node {}" , version. bold( ) . bright_red( ) ) ,
274
259
vec ! [
275
- vec![ " Only the following list is supported:". to_string ( ) ] ,
260
+ vec![ fmtln! ( "{}" , " Only the following list is supported:") ] ,
276
261
node_white_list
277
262
. iter( )
278
263
. map( |item| format!( "- {}" , item) . to_string( ) )
@@ -291,10 +276,7 @@ pub fn friendly_error_message(error: SnmError) {
291
276
format ! ( "Unsupported packageManager {}" , name. bold( ) . bright_red( ) ) ,
292
277
vec ! [
293
278
vec![
294
- format!(
295
- "The raw package manager configuration is {}, Only the following list is supported:" ,
296
- raw. bold( ) . bright_red( )
297
- ) ,
279
+ fmtln!( "The raw package manager configuration is {}, Only the following list is supported:" , raw. bold( ) . bright_red( ) ) ,
298
280
] ,
299
281
supported
300
282
. iter( )
0 commit comments