From 329158ac93b27d83876b81bb5d6a9f794d5d74ae Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Tue, 30 Aug 2022 11:15:26 +0200 Subject: [PATCH] Better error message for YAML syntax errors (#7217) Co-authored-by: Aleos --- src/common/database.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/database.cpp b/src/common/database.cpp index 36f969daf0..5885fadeec 100644 --- a/src/common/database.cpp +++ b/src/common/database.cpp @@ -106,7 +106,16 @@ bool YamlDatabase::load(const std::string& path) { fclose(f); parser = {}; - ryml::Tree tree = parser.parse_in_arena(c4::to_csubstr(path), c4::to_csubstr(buf)); + ryml::Tree tree; + + try{ + tree = parser.parse_in_arena(c4::to_csubstr(path), c4::to_csubstr(buf)); + }catch( const std::runtime_error& e ){ + ShowError( "Failed to load %s database file from '" CL_WHITE "%s" CL_RESET "'.\n", this->type.c_str(), path.c_str() ); + ShowError( "There is likely a syntax error in the file.\n" ); + ShowError( "Error message: %s\n", e.what() ); + return false; + } // Required here already for header error reporting this->currentFile = path;