@@ -9,6 +9,7 @@ use std::sync::{Arc, Mutex};
9
9
10
10
use crate :: fs:: { Metadata , Permissions } ;
11
11
use crate :: future;
12
+ use crate :: utils:: Context as _;
12
13
use crate :: io:: { self , Read , Seek , SeekFrom , Write } ;
13
14
use crate :: path:: Path ;
14
15
use crate :: prelude:: * ;
@@ -112,7 +113,11 @@ impl File {
112
113
/// ```
113
114
pub async fn open < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
114
115
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 ?;
116
121
Ok ( File :: new ( file, true ) )
117
122
}
118
123
@@ -147,7 +152,11 @@ impl File {
147
152
/// ```
148
153
pub async fn create < P : AsRef < Path > > ( path : P ) -> io:: Result < File > {
149
154
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 ?;
151
160
Ok ( File :: new ( file, true ) )
152
161
}
153
162
0 commit comments