Skip to content

Commit

Permalink
Cleanup error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rschu1ze committed Apr 16, 2024
1 parent b06ef89 commit 2ac7a44
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Functions/parseDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,27 +665,29 @@ namespace
continue;

Int64OrError result = 0;

/// Ensure all input was consumed
if (cur < end)
{
if (error_handling == ErrorHandling::Exception)
result = tl::unexpected(ErrorCodeAndMessage(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Invalid format input {} is malformed at {}",
str_ref.toView(),
std::string_view(cur, end - cur)));
result = tl::unexpected(ErrorCodeAndMessage(
ErrorCodes::CANNOT_PARSE_DATETIME,
"Invalid format input {} is malformed at {}",
str_ref.toView(),
std::string_view(cur, end - cur)));
}
if (result)

if (result.has_value())
{
if (result = datetime.buildDateTime(time_zone); result.has_value())
{
res_data[i] = static_cast<UInt32>(*result);
}
}

if (!result.has_value())
{
if constexpr (error_handling == ErrorHandling::Zero)
{
res_data[i] = 0;
}
else if constexpr (error_handling == ErrorHandling::Null)
{
res_data[i] = 0;
Expand All @@ -694,7 +696,8 @@ namespace
else
{
static_assert(error_handling == ErrorHandling::Exception);
throw Exception(result.error().error_code, "{}", result.error().error_message);
const ErrorCodeAndMessage & err = result.error();
throw Exception(err.error_code, "{}", err.error_message);
}
}
}
Expand Down

0 comments on commit 2ac7a44

Please sign in to comment.