Skip to content

Commit af18098

Browse files
pks-tgitster
authored andcommitted
reftable/error: discern locked/outdated errors
We currently throw two different errors into a similar-but-different error code: - Errors when trying to lock the reftable stack. - Errors when trying to write to the reftable stack which has been modified concurrently. This results in unclear error handling and user-visible error messages. Create a new `REFTABLE_OUTDATED_ERROR` so that those error conditions can be clearly told apart from each other. Adjust users of the old `REFTABLE_LOCK_ERROR` to use the new error code as required. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 630942a commit af18098

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

reftable/error.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const char *reftable_error_str(int err)
2222
case REFTABLE_NOT_EXIST_ERROR:
2323
return "file does not exist";
2424
case REFTABLE_LOCK_ERROR:
25-
return "data is outdated";
25+
return "data is locked";
2626
case REFTABLE_API_ERROR:
2727
return "misuse of the reftable API";
2828
case REFTABLE_ZLIB_ERROR:
@@ -35,6 +35,8 @@ const char *reftable_error_str(int err)
3535
return "invalid refname";
3636
case REFTABLE_ENTRY_TOO_BIG_ERROR:
3737
return "entry too large";
38+
case REFTABLE_OUTDATED_ERROR:
39+
return "data concurrently modified";
3840
case -1:
3941
return "general error";
4042
default:

reftable/reftable-error.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum reftable_error {
2525
*/
2626
REFTABLE_NOT_EXIST_ERROR = -4,
2727

28-
/* Trying to write out-of-date data. */
28+
/* Trying to access locked data. */
2929
REFTABLE_LOCK_ERROR = -5,
3030

3131
/* Misuse of the API:
@@ -57,6 +57,9 @@ enum reftable_error {
5757
/* Entry does not fit. This can happen when writing outsize reflog
5858
messages. */
5959
REFTABLE_ENTRY_TOO_BIG_ERROR = -11,
60+
61+
/* Trying to write out-of-date data. */
62+
REFTABLE_OUTDATED_ERROR = -12,
6063
};
6164

6265
/* convert the numeric error code to a string. The string should not be

reftable/stack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ int reftable_stack_add(struct reftable_stack *st,
529529
{
530530
int err = stack_try_add(st, write, arg);
531531
if (err < 0) {
532-
if (err == REFTABLE_LOCK_ERROR) {
532+
if (err == REFTABLE_OUTDATED_ERROR) {
533533
/* Ignore error return, we want to propagate
534-
REFTABLE_LOCK_ERROR.
534+
REFTABLE_OUTDATED_ERROR.
535535
*/
536536
reftable_stack_reload(st);
537537
}
@@ -591,7 +591,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
591591
if (err < 0)
592592
goto done;
593593
if (err > 0) {
594-
err = REFTABLE_LOCK_ERROR;
594+
err = REFTABLE_OUTDATED_ERROR;
595595
goto done;
596596
}
597597

reftable/stack_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static void test_reftable_stack_uptodate(void)
232232
EXPECT_ERR(err);
233233

234234
err = reftable_stack_add(st2, &write_test_ref, &ref2);
235-
EXPECT(err == REFTABLE_LOCK_ERROR);
235+
EXPECT(err == REFTABLE_OUTDATED_ERROR);
236236

237237
err = reftable_stack_reload(st2);
238238
EXPECT_ERR(err);

0 commit comments

Comments
 (0)