mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 09:31:59 +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) {
|
optional<std::string> ReadContent(const std::string& filename) {
|
||||||
std::ifstream cache;
|
std::ifstream cache;
|
||||||
cache.open(filename);
|
cache.open(filename);
|
||||||
if (!cache.good())
|
|
||||||
return nullopt;
|
|
||||||
|
|
||||||
|
try {
|
||||||
return std::string(std::istreambuf_iterator<char>(cache),
|
return std::string(std::istreambuf_iterator<char>(cache),
|
||||||
std::istreambuf_iterator<char>());
|
std::istreambuf_iterator<char>());
|
||||||
|
} catch (std::ios_base::failure&) {
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ReadLines(std::string filename) {
|
std::vector<std::string> ReadLines(std::string filename) {
|
||||||
|
Loading…
Reference in New Issue
Block a user