@@ -16,6 +16,7 @@ use serialize_to_javascript::{default_template, DefaultTemplate, Template};
1616use url:: Url ;
1717
1818use tauri_macros:: default_runtime;
19+ use tauri_utils:: debug_eprintln;
1920#[ cfg( feature = "isolation" ) ]
2021use tauri_utils:: pattern:: isolation:: RawIsolationPayload ;
2122use tauri_utils:: {
@@ -95,8 +96,7 @@ fn set_csp<R: Runtime>(
9596 acc. style . push ( hash. into ( ) ) ;
9697 }
9798 _csp_hash => {
98- #[ cfg( debug_assertions) ]
99- eprintln ! ( "Unknown CspHash variant encountered: {:?}" , _csp_hash)
99+ debug_eprintln ! ( "Unknown CspHash variant encountered: {:?}" , _csp_hash) ;
100100 }
101101 }
102102
@@ -514,14 +514,12 @@ impl<R: Runtime> WindowManager<R> {
514514 . to_string ( ) ;
515515
516516 if let Err ( e) = SafePathBuf :: new ( path. clone ( ) . into ( ) ) {
517- #[ cfg( debug_assertions) ]
518- eprintln ! ( "asset protocol path \" {}\" is not valid: {}" , path, e) ;
517+ debug_eprintln ! ( "asset protocol path \" {}\" is not valid: {}" , path, e) ;
519518 return HttpResponseBuilder :: new ( ) . status ( 403 ) . body ( Vec :: new ( ) ) ;
520519 }
521520
522521 if !asset_scope. is_allowed ( & path) {
523- #[ cfg( debug_assertions) ]
524- eprintln ! ( "asset protocol not configured to allow the path: {}" , path) ;
522+ debug_eprintln ! ( "asset protocol not configured to allow the path: {}" , path) ;
525523 return HttpResponseBuilder :: new ( ) . status ( 403 ) . body ( Vec :: new ( ) ) ;
526524 }
527525
@@ -543,17 +541,15 @@ impl<R: Runtime> WindowManager<R> {
543541 let mut file = match tokio:: fs:: File :: open ( path_. clone ( ) ) . await {
544542 Ok ( file) => file,
545543 Err ( e) => {
546- #[ cfg( debug_assertions) ]
547- eprintln ! ( "Failed to open asset: {}" , e) ;
544+ debug_eprintln ! ( "Failed to open asset: {}" , e) ;
548545 return ( headers, 404 , buf) ;
549546 }
550547 } ;
551548 // Get the file size
552549 let file_size = match file. metadata ( ) . await {
553550 Ok ( metadata) => metadata. len ( ) ,
554551 Err ( e) => {
555- #[ cfg( debug_assertions) ]
556- eprintln ! ( "Failed to read asset metadata: {}" , e) ;
552+ debug_eprintln ! ( "Failed to read asset metadata: {}" , e) ;
557553 return ( headers, 404 , buf) ;
558554 }
559555 } ;
@@ -568,8 +564,7 @@ impl<R: Runtime> WindowManager<R> {
568564 ) {
569565 Ok ( r) => r,
570566 Err ( e) => {
571- #[ cfg( debug_assertions) ]
572- eprintln ! ( "Failed to parse range {}: {:?}" , range, e) ;
567+ debug_eprintln ! ( "Failed to parse range {}: {:?}" , range, e) ;
573568 return ( headers, 400 , buf) ;
574569 }
575570 } ;
@@ -599,14 +594,12 @@ impl<R: Runtime> WindowManager<R> {
599594 ) ;
600595
601596 if let Err ( e) = file. seek ( std:: io:: SeekFrom :: Start ( range. start ) ) . await {
602- #[ cfg( debug_assertions) ]
603- eprintln ! ( "Failed to seek file to {}: {}" , range. start, e) ;
597+ debug_eprintln ! ( "Failed to seek file to {}: {}" , range. start, e) ;
604598 return ( headers, 422 , buf) ;
605599 }
606600
607601 if let Err ( e) = file. take ( real_length) . read_to_end ( & mut buf) . await {
608- #[ cfg( debug_assertions) ]
609- eprintln ! ( "Failed read file: {}" , e) ;
602+ debug_eprintln ! ( "Failed read file: {}" , e) ;
610603 return ( headers, 422 , buf) ;
611604 }
612605 // partial content
@@ -631,8 +624,7 @@ impl<R: Runtime> WindowManager<R> {
631624 response. mimetype ( & mime_type) . body ( data)
632625 }
633626 Err ( e) => {
634- #[ cfg( debug_assertions) ]
635- eprintln ! ( "Failed to read file: {}" , e) ;
627+ debug_eprintln ! ( "Failed to read file: {}" , e) ;
636628 response. status ( 404 ) . body ( Vec :: new ( ) )
637629 }
638630 }
@@ -756,19 +748,18 @@ impl<R: Runtime> WindowManager<R> {
756748 asset
757749 } )
758750 . or_else ( || {
759- #[ cfg( debug_assertions) ]
760- eprintln ! (
751+ debug_eprintln ! (
761752 "Asset `{}` not found; fallback to {}/index.html" ,
762- path, path
753+ path,
754+ path
763755 ) ;
764756 let fallback = format ! ( "{}/index.html" , path. as_str( ) ) . into ( ) ;
765757 let asset = assets. get ( & fallback) ;
766758 asset_path = fallback;
767759 asset
768760 } )
769761 . or_else ( || {
770- #[ cfg( debug_assertions) ]
771- eprintln ! ( "Asset `{}` not found; fallback to index.html" , path) ;
762+ debug_eprintln ! ( "Asset `{}` not found; fallback to index.html" , path) ;
772763 let fallback = AssetKey :: from ( "index.html" ) ;
773764 let asset = assets. get ( & fallback) ;
774765 asset_path = fallback;
@@ -806,8 +797,7 @@ impl<R: Runtime> WindowManager<R> {
806797 } )
807798 }
808799 Err ( e) => {
809- #[ cfg( debug_assertions) ]
810- eprintln ! ( "{:?}" , e) ; // TODO log::error!
800+ debug_eprintln ! ( "{:?}" , e) ; // TODO log::error!
811801 Err ( Box :: new ( e) )
812802 }
813803 }
0 commit comments