return null if file can't be read in documentstore

This commit is contained in:
Techatrix 2022-10-17 20:46:31 +02:00
parent 2158a201ad
commit 8fb7379d71

View File

@ -682,13 +682,13 @@ fn createDocumentFromURI(self: *DocumentStore, uri: Uri, open: bool) error{OutOf
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();
const file_path = URI.parse(self.allocator, uri) catch unreachable;
const file_path = URI.parse(self.allocator, uri) catch return null;
defer self.allocator.free(file_path);
var file = std.fs.openFileAbsolute(file_path, .{}) catch unreachable;
var file = std.fs.openFileAbsolute(file_path, .{}) catch return null;
defer file.close();
const file_contents = file.readToEndAllocOptions(self.allocator, std.math.maxInt(usize), null, @alignOf(u8), 0) catch unreachable;
const file_contents = file.readToEndAllocOptions(self.allocator, std.math.maxInt(usize), null, @alignOf(u8), 0) catch return null;
return try self.createDocument(uri, file_contents, open);
}