Skip to content

Commit

Permalink
cc dynamic_config: improve parse failure message
Browse files Browse the repository at this point in the history
commit_hash:55b092b95c1e76fa5fd16c9112e5b1e4e0578df4
  • Loading branch information
Anton3 committed Feb 13, 2025
1 parent 0352cc6 commit 8a98bed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ async def test_ok(service_client, monitor_client):

CONFIG_PATTERN = (
'Failed to parse dynamic config. '
'[a-zA-Z0-9_:]*formats::json::TypeMismatchException while parsing '
"dynamic config values. Error at path 'HTTP_CLIENT_CONNECTION_POOL_SIZE': "
'[a-zA-Z0-9_:]*formats::json::TypeMismatchException while parsing dynamic config '
"with custom DocsMap parser. Error at path 'HTTP_CLIENT_CONNECTION_POOL_SIZE': "
'Wrong type. Expected: uintValue, actual: stringValue'
)

Expand Down
5 changes: 3 additions & 2 deletions core/src/components/minimal_server_component_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ TEST_F(ServerMinimalComponentList, InvalidDynamicConfigParam) {
// This is a golden test that shows how exactly dynamic config parsing failure
// may look. Feel free to change this test if those messages ever change.
const auto expected_exception_message = fmt::format(
"Cannot start component dynamic-config: {} while parsing dynamic config values. Error at path "
"Cannot start component dynamic-config: {} while parsing dynamic config "
"USERVER_LOG_DYNAMIC_DEBUG. Error at path "
"'USERVER_LOG_DYNAMIC_DEBUG.force-enabled': Wrong type. Expected: arrayValue, actual: intValue",
// NOTE: GetTypeName(typeid(T)) for old version of compilators
// NOTE: GetTypeName(typeid(T)) for old compilers.
compiler::GetTypeName(typeid(formats::json::TypeMismatchException))
);

Expand Down
4 changes: 3 additions & 1 deletion core/src/dynamic_config/impl/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ SnapshotData::SnapshotData(const DocsMap& defaults, const std::vector<KeyValue>&
try {
user_configs_[id] = metadata.factory(defaults);
} catch (const std::exception& ex) {
const auto name =
metadata.name.empty() ? "with custom DocsMap parser" : std::string_view{metadata.name};
throw ConfigParseError(fmt::format(
"{} while parsing dynamic config values. {}", compiler::GetTypeName(typeid(ex)), ex.what()
"{} while parsing dynamic config {}. {}", compiler::GetTypeName(typeid(ex)), name, ex.what()
));
}
}
Expand Down

0 comments on commit 8a98bed

Please sign in to comment.