@@ -127,7 +127,7 @@ struct PythonFormatter<'py> {
127127/// Get the Python formatter and its configuration
128128fn get_python_formatter_with_config < ' py > ( py : Python < ' py > ) -> PyResult < PythonFormatter < ' py > > {
129129 let formatter = import_python_formatter ( py) ?;
130- let config = build_formatter_config_from_python ( & formatter) ;
130+ let config = build_formatter_config_from_python ( & formatter) ? ;
131131 Ok ( PythonFormatter { formatter, config } )
132132}
133133
@@ -137,6 +137,7 @@ fn import_python_formatter(py: Python) -> PyResult<Bound<'_, PyAny>> {
137137 let get_formatter = formatter_module. getattr ( "get_formatter" ) ?;
138138 get_formatter. call0 ( )
139139}
140+
140141// Helper function to extract attributes with fallback to default
141142fn get_attr < ' a , T > ( py_object : & ' a Bound < ' a , PyAny > , attr_name : & str , default_value : T ) -> T
142143where
@@ -149,7 +150,7 @@ where
149150}
150151
151152/// Helper function to create a FormatterConfig from a Python formatter object
152- fn build_formatter_config_from_python ( formatter : & Bound < ' _ , PyAny > ) -> FormatterConfig {
153+ fn build_formatter_config_from_python ( formatter : & Bound < ' _ , PyAny > ) -> PyResult < FormatterConfig > {
153154 let default_config = FormatterConfig :: default ( ) ;
154155 let max_bytes = get_attr ( formatter, "max_memory_bytes" , default_config. max_bytes ) ;
155156 let min_rows = get_attr ( formatter, "min_rows_display" , default_config. min_rows ) ;
@@ -161,14 +162,11 @@ fn build_formatter_config_from_python(formatter: &Bound<'_, PyAny>) -> Formatter
161162 repr_rows,
162163 } ;
163164
164- // Validate the configuration
165- if let Err ( err) = config. validate ( ) {
166- // Log the error but use default values instead of failing
167- eprintln ! ( "Invalid formatter configuration: {}" , err) ;
168- return default_config;
169- }
170-
165+ // Return the validated config, converting String error to PyErr
171166 config
167+ . validate ( )
168+ . map_err ( |e| pyo3:: exceptions:: PyValueError :: new_err ( e) ) ?;
169+ Ok ( config)
172170}
173171
174172/// A PyDataFrame is a representation of a logical plan and an API to compose statements.
0 commit comments