@@ -11,6 +11,7 @@ use ruff_python_ast::{Expr, Mod};
1111use ruff_python_parser:: { Mode , ParseOptions } ;
1212use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
1313use schemars:: { JsonSchema , Schema , SchemaGenerator } ;
14+ use tracing:: error;
1415
1516use crate :: constants:: { CONFIG_WIKI_URL } ;
1617use crate :: core:: diagnostics:: { DiagnosticCode , DiagnosticSetting , SchemaDiagnosticCodes } ;
@@ -66,13 +67,13 @@ impl Default for MergeMethod {
6667#[ derive( Debug , Deserialize , Serialize , Clone , Copy , JsonSchema ) ]
6768#[ serde( rename_all = "lowercase" ) ]
6869pub enum DiagnosticFilterPathType {
69- IN ,
70- NOT_IN
70+ In ,
71+ NotIn
7172}
7273
7374impl Default for DiagnosticFilterPathType {
7475 fn default ( ) -> Self {
75- DiagnosticFilterPathType :: IN
76+ DiagnosticFilterPathType :: In
7677 }
7778}
7879
@@ -523,7 +524,7 @@ fn process_version(var: Sourced<String>, ws_folders: &HashMap<String, String>, w
523524 } ;
524525 let config_dir = config_path. parent ( ) . map ( PathBuf :: from) . unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
525526 match fill_validate_path ( ws_folders, workspace_name, var. value ( ) , |p| PathBuf :: from ( p) . exists ( ) , HashMap :: new ( ) , & config_dir) {
526- Some ( filled_path) => {
527+ Ok ( filled_path) => {
527528 let var_pb = PathBuf :: from ( & filled_path) ;
528529 if var_pb. is_file ( ) {
529530 // If it is a file, we can return the file name
@@ -552,8 +553,11 @@ fn process_version(var: Sourced<String>, ws_folders: &HashMap<String, String>, w
552553 } ;
553554 Sourced { value : S ! ( suffix. as_os_str( ) . to_string_lossy( ) ) , sources : var. sources . clone ( ) , ..Default :: default ( ) }
554555 } ,
555- // Not a valid path, just return the variable as is
556- None => var,
556+ // Not a valid path, just return the variable as is, log info
557+ Err ( err) => {
558+ error ! ( "Failed to process $version path for variable {:?}: {}" , var, err) ;
559+ var
560+ } ,
557561 }
558562}
559563
@@ -766,7 +770,7 @@ pub fn default_profile_name() -> String {
766770 "default" . to_string ( )
767771}
768772
769- fn fill_or_canonicalize < F > ( sourced_path : & Sourced < String > , ws_folders : & HashMap < String , String > , workspace_name : Option < & String > , predicate : & F , var_map : HashMap < String , String > ) -> Option < Sourced < String > >
773+ fn fill_or_canonicalize < F > ( sourced_path : & Sourced < String > , ws_folders : & HashMap < String , String > , workspace_name : Option < & String > , predicate : & F , var_map : HashMap < String , String > ) -> Result < Sourced < String > , String >
770774where
771775F : Fn ( & String ) -> bool ,
772776{
@@ -776,19 +780,21 @@ F: Fn(&String) -> bool,
776780 let config_dir = config_path. parent ( ) . map ( PathBuf :: from) . unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
777781 if has_template ( & sourced_path. value ) {
778782 return fill_validate_path ( ws_folders, workspace_name, & sourced_path. value , predicate, var_map, & config_dir)
779- . and_then ( |p| std:: fs:: canonicalize ( PathBuf :: from ( p) ) . ok ( ) )
783+ . and_then ( |p| std:: fs:: canonicalize ( PathBuf :: from ( p) ) . map_err ( |e| e . to_string ( ) ) )
780784 . map ( |p| p. sanitize ( ) )
781785 . map ( |path| Sourced { value : path, sources : sourced_path. sources . clone ( ) , ..Default :: default ( ) } ) ;
782786 }
783787 let mut path = PathBuf :: from ( & sourced_path. value ) ;
784788 if path. is_relative ( ) {
785789 path = config_dir. join ( sourced_path. value . clone ( ) ) ;
786790 }
787- std:: fs:: canonicalize ( path)
788- . map ( |p| p. sanitize ( ) )
789- . ok ( )
790- . filter ( |p| predicate ( & p) )
791- . map ( |path| Sourced { value : path, sources : sourced_path. sources . clone ( ) , ..Default :: default ( ) } )
791+ let path = std:: fs:: canonicalize ( path)
792+ . map_err ( |e| e. to_string ( ) ) ?
793+ . sanitize ( ) ;
794+ if !predicate ( & path) {
795+ return Err ( format ! ( "Path '{}' does not satisfy the required conditions" , path) ) ;
796+ }
797+ Ok ( Sourced { value : path, sources : sourced_path. sources . clone ( ) , ..Default :: default ( ) } )
792798}
793799
794800fn process_paths (
@@ -804,7 +810,10 @@ fn process_paths(
804810 var_map. insert ( S ! ( "base" ) , b. value ( ) . clone ( ) ) ;
805811 }
806812 entry. odoo_path = entry. odoo_path . as_ref ( )
807- . and_then ( |p| fill_or_canonicalize ( p, ws_folders, workspace_name, & is_odoo_path, var_map. clone ( ) ) ) ;
813+ . and_then ( |p| fill_or_canonicalize ( p, ws_folders, workspace_name, & is_odoo_path, var_map. clone ( ) )
814+ . map_err ( |err| error ! ( "Failed to process odoo path for variable {:?}: {}" , p, err) )
815+ . ok ( )
816+ ) ;
808817
809818 let infer = entry. addons_paths . as_mut ( ) . map_or ( true , |ps| {
810819 let initial_len = ps. len ( ) ;
@@ -814,6 +823,8 @@ fn process_paths(
814823 entry. addons_paths = entry. addons_paths . as_ref ( ) . map ( |paths|
815824 paths. iter ( ) . filter_map ( |sourced| {
816825 fill_or_canonicalize ( sourced, ws_folders, workspace_name, & is_addon_path, var_map. clone ( ) )
826+ . map_err ( |err| error ! ( "Failed to process addons path for variable {:?}: {}" , sourced, err) )
827+ . ok ( )
817828 } ) . collect ( )
818829 ) ;
819830 if infer {
@@ -834,6 +845,8 @@ fn process_paths(
834845 Some ( p. clone ( ) )
835846 } else {
836847 fill_or_canonicalize ( p, ws_folders, workspace_name, & is_python_path, var_map. clone ( ) )
848+ . map_err ( |err| error ! ( "Failed to fill or canonicalize python path for variable {:?}: {}" , p, err) )
849+ . ok ( )
837850 }
838851 } ) ;
839852 entry. stdlib . as_mut ( ) . map ( |std|{
@@ -848,6 +861,27 @@ fn process_paths(
848861 }
849862 }
850863 } ) ;
864+ entry. diagnostic_filters . iter_mut ( ) . for_each ( |filter| {
865+ let Some ( config_path) = filter. sources . iter ( ) . next ( ) . map ( PathBuf :: from) else {
866+ unreachable ! ( "Expected at least one source for sourced_path: {:?}" , filter) ;
867+ } ;
868+ let config_dir = config_path. parent ( ) . map ( PathBuf :: from) . unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
869+ filter. value . paths = filter. value . paths . iter ( ) . filter_map ( |pattern| {
870+ let pattern_string = pattern. to_string ( ) ;
871+ let processed_pattern = fill_validate_path ( ws_folders, workspace_name, & pattern_string, & |_: & String | true , var_map. clone ( ) , & config_dir)
872+ . and_then ( |p| Pattern :: new ( & p)
873+ . map_err ( |e| e. to_string ( ) ) ) ;
874+ match processed_pattern {
875+ Ok ( p) => Some ( p) ,
876+ Err ( err) => {
877+ let message = format ! ( "Failed to process pattern '{}': {}" , pattern_string, err) ;
878+ filter. info = filter. info . clone ( ) + & message;
879+ error ! ( message) ;
880+ None
881+ }
882+ }
883+ } ) . collect ( ) ;
884+ } ) ;
851885}
852886
853887fn read_config_from_file < P : AsRef < Path > > ( path : P ) -> Result < HashMap < String , ConfigEntryRaw > , String > {
@@ -1167,7 +1201,7 @@ fn load_config_from_workspace(
11671201 let Some ( parent_dir) = version_path. parent ( ) else {
11681202 continue ;
11691203 } ;
1170- let Some ( parent_dir) = fill_or_canonicalize (
1204+ let Ok ( parent_dir) = fill_or_canonicalize (
11711205 & { Sourced { value : parent_dir. sanitize ( ) , sources : version_var. sources . clone ( ) , ..Default :: default ( ) } } ,
11721206 ws_folders,
11731207 Some ( workspace_name) ,
0 commit comments