1
1
use pgt_console:: fmt:: Display ;
2
2
use pgt_console:: { MarkupBuf , markup} ;
3
+ use pgt_diagnostics:: adapters:: ResolveError ;
4
+
3
5
use pgt_diagnostics:: { Advices , Diagnostic , Error , LogCategory , MessageAndDescription , Visit } ;
4
6
use serde:: { Deserialize , Serialize } ;
5
7
use std:: fmt:: { Debug , Formatter } ;
@@ -21,6 +23,12 @@ pub enum ConfigurationDiagnostic {
21
23
22
24
/// Thrown when the pattern inside the `ignore` field errors
23
25
InvalidIgnorePattern ( InvalidIgnorePattern ) ,
26
+
27
+ /// Thrown when there's something wrong with the files specified inside `"extends"`
28
+ CantLoadExtendFile ( CantLoadExtendFile ) ,
29
+
30
+ /// Thrown when a configuration file can't be resolved from `node_modules`
31
+ CantResolve ( CantResolve ) ,
24
32
}
25
33
26
34
impl ConfigurationDiagnostic {
@@ -72,6 +80,18 @@ impl ConfigurationDiagnostic {
72
80
message : MessageAndDescription :: from ( markup ! { { message} } . to_owned ( ) ) ,
73
81
} )
74
82
}
83
+
84
+ pub fn cant_resolve ( path : impl Display , source : oxc_resolver:: ResolveError ) -> Self {
85
+ Self :: CantResolve ( CantResolve {
86
+ message : MessageAndDescription :: from (
87
+ markup ! {
88
+ "Failed to resolve the configuration from " { { path} }
89
+ }
90
+ . to_owned ( ) ,
91
+ ) ,
92
+ source : Some ( Error :: from ( ResolveError :: from ( source) ) ) ,
93
+ } )
94
+ }
75
95
}
76
96
77
97
impl Debug for ConfigurationDiagnostic {
@@ -168,3 +188,36 @@ pub struct CantResolve {
168
188
#[ source]
169
189
source : Option < Error > ,
170
190
}
191
+
192
+ #[ derive( Debug , Serialize , Deserialize , Diagnostic ) ]
193
+ #[ diagnostic(
194
+ category = "configuration" ,
195
+ severity = Error ,
196
+ ) ]
197
+ pub struct CantLoadExtendFile {
198
+ #[ location( resource) ]
199
+ file_path : String ,
200
+ #[ message]
201
+ #[ description]
202
+ message : MessageAndDescription ,
203
+
204
+ #[ verbose_advice]
205
+ verbose_advice : ConfigurationAdvices ,
206
+ }
207
+
208
+ impl CantLoadExtendFile {
209
+ pub fn new ( file_path : impl Into < String > , message : impl Display ) -> Self {
210
+ Self {
211
+ file_path : file_path. into ( ) ,
212
+ message : MessageAndDescription :: from ( markup ! { { message} } . to_owned ( ) ) ,
213
+ verbose_advice : ConfigurationAdvices :: default ( ) ,
214
+ }
215
+ }
216
+
217
+ pub fn with_verbose_advice ( mut self , messsage : impl Display ) -> Self {
218
+ self . verbose_advice
219
+ . messages
220
+ . push ( markup ! { { messsage} } . to_owned ( ) ) ;
221
+ self
222
+ }
223
+ }
0 commit comments