From: Junio C Hamano <gitster@pobox.com>
To: Meet Soni <meetsoni3017@gmail.com>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
Han-Wen Nienhuys <hanwen@google.com>
Subject: Re: [GSoC PATCH] reftable: return proper error code from block_writer_add()
Date: Thu, 06 Mar 2025 09:04:01 -0800 [thread overview]
Message-ID: <xmqqsenqhz0e.fsf@gitster.g> (raw)
In-Reply-To: <20250306121324.1315290-1-meetsoni3017@gmail.com> (Meet Soni's message of "Thu, 6 Mar 2025 17:43:24 +0530")
Meet Soni <meetsoni3017@gmail.com> writes:
> Previously, block_writer_add() used to return generic -1, which forced
> an assumption about the error type.
>
> Replace generic -1 returns in block_writer_add() and related functions
> with defined error codes.
What's missing from this proposed log message is an audit of the
callers to tell readers that this change is safe and expected by the
callers. IOW, are there callers that start to behave differently
when they see ENTRY_TOO_BIG instead of -1, for example?
> Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
> ---
> This patch attempts to avoid making an assumption regarding error codes
> returned by block_writer_add().
> reftable/block.c | 9 +++++----
> reftable/record.c | 16 +++++++++++-----
> reftable/writer.c | 8 +-------
> 3 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/reftable/block.c b/reftable/block.c
> index b14a8f1259..50fbac801a 100644
> --- a/reftable/block.c
> +++ b/reftable/block.c
> @@ -49,7 +49,7 @@ static int block_writer_register_restart(struct block_writer *w, int n,
> if (is_restart)
> rlen++;
> if (2 + 3 * rlen + n > w->block_size - w->next)
> - return -1;
> + return REFTABLE_ENTRY_TOO_BIG_ERROR;
So this makes block_writer_register_restart() to return -11 instead
of -1; the sole caller of the function is block_writer_add() that
begins like so:
/* Adds the reftable_record to the block. Returns -1 if it does not fit, 0 on
success. Returns REFTABLE_API_ERROR if attempting to write a record with
empty key. */
int block_writer_add(struct block_writer *w, struct reftable_record *rec)
{
Needless to say, the comment before the function needs to be
adjusted together with the above hunk (and others). But more
importantly, are existing callers of this function now expected to
adjust to the change in behaviour when they receive the return value
of this function? It used to be sufficient for them to deal with
-1, 0 or API_ERROR, but now they are required to handle other errors
(like the one that comes back from reftable_encode_key(). Do they
already handle these new error codes just fine? Have you traced the
code paths to see how they react to them?
> @@ -115,8 +115,9 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec)
> int err;
>
> err = reftable_record_key(rec, &w->scratch);
> - if (err < 0)
> + if (err < 0) {
> goto done;
> + }
This is unwarranted, isn't it?
> @@ -126,14 +127,14 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec)
> n = reftable_encode_key(&is_restart, out, last, w->scratch,
> reftable_record_val_type(rec));
> if (n < 0) {
> - err = -1;
> + err = n;
> goto done;
> }
Here, block_writer_add() starts returning new error codes to its
callers that it never returned.
> string_view_consume(&out, n);
>
> n = reftable_record_encode(rec, out, w->hash_size);
> if (n < 0) {
> - err = -1;
> + err = n;
> goto done;
> }
Ditto.
Note that I am not saying that it is a bad idea to make the error
codes more specific so that the callers can tell them apart. I am
only saying that the patch that makes such a change must also make
sure that the callers are prepared to handle error coes that they
have never seen from the current callee.
The same applies to the remainder of the patch.
Thanks.
next prev parent reply other threads:[~2025-03-06 17:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 12:13 [GSoC PATCH] reftable: return proper error code from block_writer_add() Meet Soni
2025-03-06 14:43 ` Patrick Steinhardt
2025-03-06 17:04 ` Junio C Hamano [this message]
2025-03-08 13:33 ` [GSoC PATCH v2] " Meet Soni
2025-03-12 8:23 ` Patrick Steinhardt
2025-03-12 12:11 ` [GSoC PATCH v3 0/2] reftable: return proper error codes from block_writer_add Meet Soni
2025-03-12 12:11 ` [PATCH v3 1/2] reftable: propagate specific error codes in block_writer_add() Meet Soni
2025-03-12 12:11 ` [PATCH v3 2/2] reftable: adapt writer code to propagate block_writer_add() errors Meet Soni
2025-03-12 12:49 ` Patrick Steinhardt
2025-03-13 15:29 ` Meet Soni
2025-03-19 13:18 ` Patrick Steinhardt
2025-03-19 7:59 ` [GSoC PATCH v4 0/3] reftable: return proper error codes from block_writer_add Meet Soni
2025-03-19 7:59 ` [PATCH v4 1/3] reftable: propagate specific error codes in block_writer_add() Meet Soni
2025-03-19 7:59 ` [PATCH v4 2/3] reftable: adapt writer_add_record() to propagate block_writer_add() errors Meet Soni
2025-03-19 7:59 ` [PATCH v4 3/3] reftable: adapt write_object_record() " Meet Soni
2025-03-19 15:29 ` [GSoC PATCH v5 0/3] reftable: return proper error codes from block_writer_add Meet Soni
2025-03-19 15:29 ` [GSoC PATCH v5 1/3] reftable: propagate specific error codes in block_writer_add() Meet Soni
2025-03-19 15:29 ` [GSoC PATCH v5 2/3] reftable: adapt writer_add_record() to propagate block_writer_add() errors Meet Soni
2025-03-19 15:29 ` [GSoC PATCH v5 3/3] reftable: adapt write_object_record() " Meet Soni
2025-03-19 15:48 ` [GSoC PATCH v5 0/3] reftable: return proper error codes from block_writer_add Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqsenqhz0e.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=hanwen@google.com \
--cc=meetsoni3017@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).