@@ -300,7 +300,6 @@ pub struct CurveFitApp {
300300 pub ( super ) result_metrics : Option < ExtendedMetrics > ,
301301 pub ( super ) residual_plot_points : Vec < PlotPoint > ,
302302 pub ( super ) spline_plot_curve : Option < Arc < [ PlotPoint ] > > ,
303- #[ cfg( not( target_arch = "wasm32" ) ) ]
304303 pub ( super ) formula_svg_cache : Option < FormulaSvgCache > ,
305304 pub ( super ) sampled_curve_cache : Option < SampledCurveCache > ,
306305 pub ( super ) iteration_diagnostics : IterationDiagnostics ,
@@ -555,28 +554,37 @@ impl CurveFitApp {
555554 )
556555 }
557556
558- #[ cfg( not( target_arch = "wasm32" ) ) ]
559557 pub ( super ) fn cached_formula_svg (
560558 & mut self ,
561559 formula : & str ,
562560 dark_mode : bool ,
563- ) -> ( String , Arc < [ u8 ] > ) {
561+ ) -> Result < ( String , Arc < [ u8 ] > ) , String > {
564562 if let Some ( cache) = & self . formula_svg_cache
565563 && cache. formula == formula
566564 && cache. dark_mode == dark_mode
567565 {
568- return ( cache. uri . clone ( ) , Arc :: clone ( & cache. bytes ) ) ;
566+ return cache
567+ . render_result
568+ . as_ref ( )
569+ . map ( |bytes| ( cache. uri . clone ( ) , Arc :: clone ( bytes) ) )
570+ . map_err ( |error| error. clone ( ) ) ;
569571 }
570572
571573 let uri = formula_svg_uri ( formula, dark_mode) ;
572- let bytes: Arc < [ u8 ] > = formula_svg_bytes ( formula, dark_mode) . into ( ) ;
574+ let render_result = match formula_svg_bytes ( formula, dark_mode) {
575+ Ok ( bytes) => Ok ( Arc :: < [ u8 ] > :: from ( bytes) ) ,
576+ Err ( error) => {
577+ eprintln ! ( "Failed to render formula SVG: {error}" ) ;
578+ Err ( error)
579+ }
580+ } ;
573581 self . formula_svg_cache = Some ( FormulaSvgCache {
574582 formula : formula. to_string ( ) ,
575583 dark_mode,
576584 uri : uri. clone ( ) ,
577- bytes : Arc :: clone ( & bytes ) ,
585+ render_result : render_result . clone ( ) ,
578586 } ) ;
579- ( uri, bytes)
587+ render_result . map ( |bytes| ( uri, bytes) )
580588 }
581589
582590 pub ( super ) fn cached_sampled_curve (
0 commit comments