@@ -57,7 +57,12 @@ pub struct Files {
5757
5858impl Files {
5959 pub fn file_text ( & self , file_id : vfs:: FileId ) -> FileText {
60- * self . files . get ( & file_id) . expect ( "Unable to fetch file; this is a bug" )
60+ match self . files . get ( & file_id) {
61+ Some ( text) => * text,
62+ None => {
63+ panic ! ( "Unable to fetch file text for `vfs::FileId`: {:?}; this is a bug" , file_id)
64+ }
65+ }
6166 }
6267
6368 pub fn set_file_text ( & self , db : & mut dyn SourceDatabase , file_id : vfs:: FileId , text : & str ) {
@@ -93,10 +98,13 @@ impl Files {
9398
9499 /// Source root of the file.
95100 pub fn source_root ( & self , source_root_id : SourceRootId ) -> SourceRootInput {
96- let source_root = self
97- . source_roots
98- . get ( & source_root_id)
99- . expect ( "Unable to fetch source root id; this is a bug" ) ;
101+ let source_root = match self . source_roots . get ( & source_root_id) {
102+ Some ( source_root) => source_root,
103+ None => panic ! (
104+ "Unable to fetch `SourceRootInput` with `SourceRootId` ({:?}); this is a bug" ,
105+ source_root_id
106+ ) ,
107+ } ;
100108
101109 * source_root
102110 }
@@ -121,10 +129,13 @@ impl Files {
121129 }
122130
123131 pub fn file_source_root ( & self , id : vfs:: FileId ) -> FileSourceRootInput {
124- let file_source_root = self
125- . file_source_roots
126- . get ( & id)
127- . expect ( "Unable to fetch FileSourceRootInput; this is a bug" ) ;
132+ let file_source_root = match self . file_source_roots . get ( & id) {
133+ Some ( file_source_root) => file_source_root,
134+ None => panic ! (
135+ "Unable to get `FileSourceRootInput` with `vfs::FileId` ({:?}); this is a bug" ,
136+ id
137+ ) ,
138+ } ;
128139 * file_source_root
129140 }
130141
0 commit comments