Skip to content

Commit

Permalink
Improve error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Mar 30, 2024
1 parent 82f6621 commit 152d4ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions include/tao/config/internal/config_action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "key1_guard.hpp"
#include "pegtl.hpp"
#include "phase1_append.hpp"
#include "string_utility.hpp"

namespace tao::config::internal
{
Expand Down Expand Up @@ -169,11 +170,12 @@ namespace tao::config::internal
pegtl::parse_nested< rules::config_file, config_action >( ai.position(), static_cast< pegtl_input_t& >( in ), st, fm );
}
catch( const std::system_error& e ) {
if( ( !st.include_is_optional ) || ( e.code().value() != ENOENT ) ) {
throw pegtl::parse_error( "include error", ai.position() );
// throw pegtl::parse_error( format( __FILE__, __LINE__, "include failed", { { "filename", f }, { "error", e.what() }, { "errno", e.code().value() } } ), pos );
if( !st.include_is_optional ) {
throw pegtl::parse_error( strcat( "include error: ", e.what() ), ai.position() );
}
if( e.code().value() != ENOENT ) {
throw pegtl::parse_error( strcat( "include optional error: ", e.what() ), ai.position() );
}
// An optional include file does not exist -- silently ignore and continue with a smile :-)
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/doc_include.success
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ foo
}

// Use include? with a non-existing file, not an error.
(include? "tests/non_existing_file_is_no_error_with_include?")
(include? "tests/non_existing_file_is_no_error_with_question_mark")

0 comments on commit 152d4ed

Please sign in to comment.