@@ -93,6 +93,29 @@ impl Default for FormatterConfig {
9393 }
9494}
9595
96+ impl FormatterConfig {
97+ /// Validates that all configuration values are positive integers.
98+ ///
99+ /// # Returns
100+ ///
101+ /// `Ok(())` if all values are valid, or an `Err` with a descriptive error message.
102+ pub fn validate ( & self ) -> Result < ( ) , String > {
103+ if self . max_bytes == 0 {
104+ return Err ( "max_bytes must be a positive integer" . to_string ( ) ) ;
105+ }
106+
107+ if self . min_rows == 0 {
108+ return Err ( "min_rows must be a positive integer" . to_string ( ) ) ;
109+ }
110+
111+ if self . repr_rows == 0 {
112+ return Err ( "repr_rows must be a positive integer" . to_string ( ) ) ;
113+ }
114+
115+ Ok ( ( ) )
116+ }
117+ }
118+
96119/// Holds the Python formatter and its configuration
97120struct PythonFormatter < ' py > {
98121 /// The Python formatter object
@@ -129,11 +152,20 @@ fn build_formatter_config_from_python(formatter: &Bound<'_, PyAny>) -> Formatter
129152 let min_rows = get_attr ( formatter, "min_rows_display" , default_config. min_rows ) ;
130153 let repr_rows = get_attr ( formatter, "repr_rows" , default_config. repr_rows ) ;
131154
132- FormatterConfig {
155+ let config = FormatterConfig {
133156 max_bytes,
134157 min_rows,
135158 repr_rows,
159+ } ;
160+
161+ // Validate the configuration
162+ if let Err ( err) = config. validate ( ) {
163+ // Log the error but use default values instead of failing
164+ eprintln ! ( "Invalid formatter configuration: {}" , err) ;
165+ return default_config;
136166 }
167+
168+ config
137169}
138170
139171/// A PyDataFrame is a representation of a logical plan and an API to compose statements.
0 commit comments