Skip to content

Commit

Permalink
Add stronger exception guarantees to bool serialization
Browse files Browse the repository at this point in the history
before this change the output column may or may not
contain an invalid value when an exception was thrown.
We now make sure that, in case of error, we either don't
make changes or we revert them.
  • Loading branch information
aiven-sal committed Sep 13, 2023
1 parent c5688d3 commit 62d06a0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DataTypes/Serializations/SerializationBool.cpp
Expand Up @@ -166,13 +166,13 @@ void deserializeImpl(
buf.rollbackToCheckpoint();
if (checkString(settings.bool_false_representation, buf) && check_end_of_value(buf))
{
col->insert(false);
buf.dropCheckpoint();
if (buf.hasUnreadData())
throw Exception(
ErrorCodes::CANNOT_PARSE_BOOL,
"Cannot continue parsing after parsed bool value because it will result in the loss of some data. It may happen if "
"bool_true_representation or bool_false_representation contains some delimiters of input format");
col->insert(false);
return;
}

Expand All @@ -181,15 +181,19 @@ void deserializeImpl(
{
buf.dropCheckpoint();
if (buf.hasUnreadData())
{
col->popBack(1);
throw Exception(
ErrorCodes::CANNOT_PARSE_BOOL,
"Cannot continue parsing after parsed bool value because it will result in the loss of some data. It may happen if "
"bool_true_representation or bool_false_representation contains some delimiters of input format");
}
return;
}

buf.makeContinuousMemoryFromCheckpointToPos();
buf.rollbackToCheckpoint();
col->popBack(1);
throw Exception(
ErrorCodes::CANNOT_PARSE_BOOL,
"Cannot parse boolean value here: '{}', should be '{}' or '{}' controlled by setting bool_true_representation and "
Expand Down

0 comments on commit 62d06a0

Please sign in to comment.