Subject: [PATCH v4 14/29] rebase: die on invalid trailer args

From: Li Chen <[email-masked]>
Date: Tue, 14 Oct 2025 20:24:27 +0800

This can simplify the error handle in
validate_trailer_args_after_config and
its caller.

Signed-off-by: Li Chen <[email-masked]>
---
 builtin/rebase.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index cc90980d7d..872945a897 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1124,29 +1124,22 @@ static int check_exec_cmd(const char *cmd)
 	return 0;
 }
 
-static int validate_trailer_args_after_config(const struct strvec *cli_args,
-				       struct strbuf *err)
+static void validate_trailer_args_after_config(const struct strvec *cli_args)
 {
 	for (size_t i = 0; i < cli_args->nr; i++) {
 		const char *txt = cli_args->v[i]; // Key[:=]Val
 		const char *sep;
 
-		if (!*txt) {
-			strbuf_addstr(err, _("empty --trailer argument"));
-			return -1;
-		}
+		if (!*txt)
+			die(_("empty --trailer argument"));
 
 		sep = strpbrk(txt, ":=");
 
 		/* there must be key bfore seperator */
-		if (sep && sep == txt) {
-			strbuf_addf(err,
-				    _("invalid trailer '%s': missing key before separator"),
-				    txt);
-			return -1;
-		}
+		if (sep && sep == txt)
+			die(_("invalid trailer '%s': missing key before separator"),
+			    txt);
 	}
-	return 0;
 }
 
 int cmd_rebase(int argc,
@@ -1353,13 +1346,8 @@ int cmd_rebase(int argc,
 			     builtin_rebase_usage, 0);
 
 	if (options.trailer_args.nr) {
-		struct strbuf err = STRBUF_INIT;
-
-		if (validate_trailer_args_after_config(&options.trailer_args, &err))
-			die("%s", err.buf);
-
+		validate_trailer_args_after_config(&options.trailer_args);
 		options.flags |= REBASE_FORCE;
-		strbuf_release(&err);
 	}
 
 	if (preserve_merges_selected)
-- 
2.51.0