Skip to content

Commit 54b09e7

Browse files
committed
fix: review comments
1 parent a752c91 commit 54b09e7

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/iceberg/util/decimal.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,18 @@
2424

2525
#include "iceberg/util/decimal.h"
2626

27-
#include <array>
2827
#include <bit>
2928
#include <charconv>
3029
#include <climits>
3130
#include <cmath>
32-
#include <cstdint>
3331
#include <cstring>
3432
#include <format>
3533
#include <iomanip>
3634
#include <limits>
3735
#include <sstream>
38-
#include <string>
39-
#include <string_view>
4036
#include <utility>
4137

38+
#include "iceberg/exception.h"
4239
#include "iceberg/result.h"
4340
#include "iceberg/util/int128.h"
4441
#include "iceberg/util/macros.h"
@@ -287,9 +284,8 @@ bool RescaleWouldCauseDataLoss(const Decimal& value, int32_t delta_scale,
287284
Decimal::Decimal(std::string_view str) {
288285
auto result = Decimal::FromString(str);
289286
if (!result) {
290-
throw std::runtime_error(
291-
std::format("Failed to parse Decimal from string: {}, error: {}", str,
292-
result.error().message));
287+
throw IcebergError(std::format("Failed to parse Decimal from string: {}, error: {}",
288+
str, result.error().message));
293289
}
294290
*this = std::move(result.value());
295291
}

src/iceberg/util/decimal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ class ICEBERG_EXPORT Decimal : public util::Formattable {
5252
constexpr Decimal() noexcept = default;
5353

5454
/// \brief Create a Decimal from a 128-bit integer.
55-
constexpr Decimal(int128_t value) noexcept // NOLINT(google-explicit-constructor)
55+
constexpr Decimal(int128_t value) noexcept // NOLINT implicit conversion
5656
: data_(value) {}
5757

5858
/// \brief Create a Decimal from any integer not wider than 64 bits.
5959
template <typename T>
6060
requires(std::is_integral_v<T> && (sizeof(T) <= sizeof(uint64_t)))
61-
constexpr Decimal(T value) noexcept // NOLINT(google-explicit-constructor)
62-
{
63-
data_ = static_cast<int128_t>(value);
64-
}
61+
constexpr Decimal(T value) noexcept // NOLINT implicit conversion
62+
: data_(static_cast<int128_t>(value)) {}
6563

6664
/// \brief Parse a Decimal from a string representation.
65+
/// \throw This constructor throws an exception if parsing fails. Use
66+
/// Decimal::FromString() if you want to handle errors more gracefully.
6767
explicit Decimal(std::string_view str);
6868

6969
/// \brief Create a Decimal from two 64-bit integers.

0 commit comments

Comments
 (0)