Skip to content

Commit bccda6d

Browse files
committed
improve error handling
1 parent 8593205 commit bccda6d

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

google/cloud/spanner/uuid.cc

+2-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace {
2929
// as 8 bytes.
3030
StatusOr<std::uint64_t> ParseHexBlock(absl::string_view& str,
3131
absl::string_view original_str) {
32-
constexpr int kMaxUuidNumberOfHexDigits = 32;
32+
constexpr int kUuidNumberOfHexDigits = 32;
3333
constexpr int kMaxUuidBlockLength = 16;
3434
static auto const* char_to_hex = new std::unordered_map<char, std::uint8_t>(
3535
{{'0', 0x00}, {'1', 0x01}, {'2', 0x02}, {'3', 0x03}, {'4', 0x04},
@@ -43,7 +43,7 @@ StatusOr<std::uint64_t> ParseHexBlock(absl::string_view& str,
4343
if (str.empty()) {
4444
return internal::InvalidArgumentError(
4545
absl::StrFormat("UUID must contain %d hexadecimal digits: %s",
46-
kMaxUuidNumberOfHexDigits, original_str),
46+
kUuidNumberOfHexDigits, original_str),
4747
GCP_ERROR_INFO());
4848
}
4949
auto it = char_to_hex->find(str[0]);
@@ -112,11 +112,6 @@ Uuid::operator std::string() const {
112112
}
113113

114114
StatusOr<Uuid> MakeUuid(absl::string_view str) {
115-
if (str.empty()) {
116-
return internal::InvalidArgumentError(
117-
absl::StrFormat("UUID cannot be empty"), GCP_ERROR_INFO());
118-
}
119-
120115
std::string original_str = std::string(str);
121116
// Check and remove optional braces
122117
if (absl::ConsumePrefix(&str, "{")) {

google/cloud/spanner/uuid_test.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ INSTANTIATE_TEST_SUITE_P(
112112
MakeUuid, MakeUuidTest,
113113
testing::Values(
114114
// Error Paths
115-
MakeUuidTestParam{
116-
"Empty", "", 0x0, 0x0,
117-
Status{StatusCode::kInvalidArgument, "UUID cannot be empty"}},
115+
MakeUuidTestParam{"Empty", "", 0x0, 0x0,
116+
Status{StatusCode::kInvalidArgument,
117+
"UUID must contain 32 hexadecimal digits"}},
118+
MakeUuidTestParam{"EmptyCurlyBraces", "{}", 0x0, 0x0,
119+
Status{StatusCode::kInvalidArgument,
120+
"UUID must contain 32 hexadecimal digits"}},
118121
MakeUuidTestParam{
119122
"MissingClosingCurlyBrace", "{0b6ed04ca16dfc4652817f9978c13738",
120123
0x0, 0x0,

0 commit comments

Comments
 (0)