mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Catch ios_base::failure exceptions in ReadContent
`filename` may be a directory (the latest Emacs lsp-mode sometimes sends a `textDocument/didOpen` message with an empty filename) or the file cannot be read.
This commit is contained in:
parent
7d06ff212f
commit
dba27c3d34
@ -229,11 +229,13 @@ std::istream& SafeGetline(std::istream& is, std::string& t) {
|
||||
optional<std::string> ReadContent(const std::string& filename) {
|
||||
std::ifstream cache;
|
||||
cache.open(filename);
|
||||
if (!cache.good())
|
||||
return nullopt;
|
||||
|
||||
try {
|
||||
return std::string(std::istreambuf_iterator<char>(cache),
|
||||
std::istreambuf_iterator<char>());
|
||||
} catch (std::ios_base::failure&) {
|
||||
return nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ReadLines(std::string filename) {
|
||||
|
Loading…
Reference in New Issue
Block a user