@@ -9,6 +9,7 @@ use std::sync::{Arc, Mutex};
99
1010use crate :: fs:: { Metadata , Permissions } ;
1111use crate :: future;
12+ use crate :: utils:: Context as _;
1213use crate :: io:: { self , Read , Seek , SeekFrom , Write } ;
1314use crate :: path:: Path ;
1415use crate :: prelude:: * ;
@@ -112,7 +113,11 @@ impl File {
112113 /// ```
113114 pub async fn open < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
114115 let path = path. as_ref ( ) . to_owned ( ) ;
115- let file = spawn_blocking ( move || std:: fs:: File :: open ( & path) ) . await ?;
116+ let file = spawn_blocking ( move || {
117+ std:: fs:: File :: open ( & path)
118+ . context ( || format ! ( "Could not open {}" , path. display( ) ) )
119+ } )
120+ . await ?;
116121 Ok ( File :: new ( file, true ) )
117122 }
118123
@@ -147,7 +152,11 @@ impl File {
147152 /// ```
148153 pub async fn create < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
149154 let path = path. as_ref ( ) . to_owned ( ) ;
150- let file = spawn_blocking ( move || std:: fs:: File :: create ( & path) ) . await ?;
155+ let file = spawn_blocking ( move || {
156+ std:: fs:: File :: create ( & path)
157+ . context ( || format ! ( "Could not create {}" , path. display( ) ) )
158+ } )
159+ . await ?;
151160 Ok ( File :: new ( file, true ) )
152161 }
153162
0 commit comments