@@ -57,7 +57,12 @@ pub struct Files {
57
57
58
58
impl Files {
59
59
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
+ }
61
66
}
62
67
63
68
pub fn set_file_text ( & self , db : & mut dyn SourceDatabase , file_id : vfs:: FileId , text : & str ) {
@@ -93,10 +98,13 @@ impl Files {
93
98
94
99
/// Source root of the file.
95
100
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
+ } ;
100
108
101
109
* source_root
102
110
}
@@ -121,10 +129,13 @@ impl Files {
121
129
}
122
130
123
131
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
+ } ;
128
139
* file_source_root
129
140
}
130
141
0 commit comments