@@ -203,15 +203,17 @@ fn render_pkg_readme<R: Read>(mut archive: Archive<R>, pkg_name: &str) -> Option
203
203
204
204
let manifest: Manifest = {
205
205
let path = format ! ( "{}/Cargo.toml" , pkg_name) ;
206
- let contents = find_file_by_path ( & mut entries, Path :: new ( & path) , pkg_name) ;
206
+ let contents = find_file_by_path ( & mut entries, Path :: new ( & path) , pkg_name)
207
+ . unwrap_or_else ( || panic ! ( "[{}] couldn't open file: Cargo.toml" , pkg_name) ) ;
207
208
toml:: from_str ( & contents)
208
209
. unwrap_or_else ( |_| panic ! ( "[{}] Syntax error in manifest file" , pkg_name) )
209
210
} ;
210
211
211
212
let rendered = {
212
213
let readme_path = manifest. package . readme . as_ref ( ) ?;
213
214
let path = format ! ( "{}/{}" , pkg_name, readme_path) ;
214
- let contents = find_file_by_path ( & mut entries, Path :: new ( & path) , pkg_name) ;
215
+ let contents = find_file_by_path ( & mut entries, Path :: new ( & path) , pkg_name)
216
+ . unwrap_or_else ( || panic ! ( "[{}] couldn't open file: {}" , pkg_name, readme_path) ) ;
215
217
text_to_html (
216
218
& contents,
217
219
readme_path,
@@ -237,7 +239,7 @@ fn find_file_by_path<R: Read>(
237
239
entries : & mut tar:: Entries < ' _ , R > ,
238
240
path : & Path ,
239
241
pkg_name : & str ,
240
- ) -> String {
242
+ ) -> Option < String > {
241
243
let mut file = entries
242
244
. find ( |entry| match * entry {
243
245
Err ( _) => false ,
@@ -248,14 +250,13 @@ fn find_file_by_path<R: Read>(
248
250
} ;
249
251
filepath == path
250
252
}
251
- } )
252
- . unwrap_or_else ( || panic ! ( "[{}] couldn't open file: {}" , pkg_name, path. display( ) ) )
253
+ } ) ?
253
254
. unwrap_or_else ( |_| panic ! ( "[{}] file is not present: {}" , pkg_name, path. display( ) ) ) ;
254
255
255
256
let mut contents = String :: new ( ) ;
256
257
file. read_to_string ( & mut contents)
257
258
. unwrap_or_else ( |_| panic ! ( "[{}] Couldn't read file contents" , pkg_name) ) ;
258
- contents
259
+ Some ( contents)
259
260
}
260
261
261
262
#[ cfg( test) ]
0 commit comments