11use pgt_console:: fmt:: Display ;
22use pgt_console:: { MarkupBuf , markup} ;
3+ use pgt_diagnostics:: adapters:: ResolveError ;
4+
35use pgt_diagnostics:: { Advices , Diagnostic , Error , LogCategory , MessageAndDescription , Visit } ;
46use serde:: { Deserialize , Serialize } ;
57use std:: fmt:: { Debug , Formatter } ;
@@ -21,6 +23,12 @@ pub enum ConfigurationDiagnostic {
2123
2224 /// Thrown when the pattern inside the `ignore` field errors
2325 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 ) ,
2432}
2533
2634impl ConfigurationDiagnostic {
@@ -72,6 +80,18 @@ impl ConfigurationDiagnostic {
7280 message : MessageAndDescription :: from ( markup ! { { message} } . to_owned ( ) ) ,
7381 } )
7482 }
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+ }
7595}
7696
7797impl Debug for ConfigurationDiagnostic {
@@ -168,3 +188,36 @@ pub struct CantResolve {
168188 #[ source]
169189 source : Option < Error > ,
170190}
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