fix(shell/lean): catch errors when loading bad cache file

This commit is contained in:
Leonardo de Moura 2015-01-15 18:06:02 -08:00
parent 30817aa2b1
commit ddcc8de09e

View file

@ -483,10 +483,16 @@ int main(int argc, char ** argv) {
definition_cache cache; definition_cache cache;
definition_cache * cache_ptr = nullptr; definition_cache * cache_ptr = nullptr;
if (use_cache) { if (use_cache) {
cache_ptr = &cache; try {
std::ifstream in(cache_name, std::ifstream::binary); cache_ptr = &cache;
if (!in.bad() && !in.fail()) std::ifstream in(cache_name, std::ifstream::binary);
cache.load(in); if (!in.bad() && !in.fail())
cache.load(in);
} catch (lean::throwable & ex) {
lean::display_error(diagnostic(env, ios), nullptr, ex);
std::cerr << "Failed to load cache file '" << cache_name << "'\n";
return 1;
}
} }
declaration_index index; declaration_index index;
declaration_index * index_ptr = nullptr; declaration_index * index_ptr = nullptr;