Add a FatalUserError macro to help print user-caused errors. (#668)

This commit is contained in:
Jon Meow
2021-07-21 12:38:56 -07:00
committed by GitHub
parent f3cbfc04c6
commit 034f3600e3
15 changed files with 102 additions and 26 deletions
+6 -8
View File
@@ -6,6 +6,8 @@
#include <iostream>
#include "common/check.h"
#include "executable_semantics/common/error.h"
#include "executable_semantics/common/tracing_flag.h"
#include "executable_semantics/syntax/parse_and_lex_context.h"
#include "executable_semantics/syntax/parser.h"
@@ -21,9 +23,8 @@ auto parse(const std::string& input_file_name)
-> std::variant<AST, SyntaxErrorCode> {
yyin = fopen(input_file_name.c_str(), "r");
if (yyin == nullptr) {
std::cerr << "Error opening '" << input_file_name
<< "': " << std::strerror(errno) << std::endl;
exit(1);
FatalUserError() << "Error opening '" << input_file_name
<< "': " << std::strerror(errno);
}
std::optional<AST> parsed_input = std::nullopt;
@@ -38,11 +39,8 @@ auto parse(const std::string& input_file_name)
return syntax_error_code;
}
if (parsed_input == std::nullopt) {
std::cerr << "Internal error: parser validated syntax yet didn't produce "
"an AST.\n";
exit(1);
}
CHECK(parsed_input != std::nullopt)
<< "parser validated syntax yet didn't produce an AST.";
return *parsed_input;
}