Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Jan Tojnar <jtojnar@gmail.com>
To: cocci@inria.fr
Cc: Jan Tojnar <jtojnar@gmail.com>
Subject: [cocci] [PATCH] Exit with non-zero status when spatch on a directory fails
Date: Mon,  5 Sep 2022 00:50:06 +0200	[thread overview]
Message-ID: <20220904225006.3438769-1-jtojnar@gmail.com> (raw)

When an error occurs during patching of a file, the process terminates
with a 255 exit code.

    spatch docs/dev/file-path-error.cocci docs/dev/test1.c

This was not the case when trying to apply the patch on a directory:

    spatch docs/dev/file-path-error.cocci docs/dev/

The process would print errors for each file individually,
and then finish with a zero (success) exit code.
Additionally, it would write out files for files that succeeded.

Let’s exit with 255 when failure occurs during the mass patching
as well, and prevent writing the changes of successful transformations
to avoid the chance of accidentally not noticing the failure.
---
 enter.ml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/enter.ml b/enter.ml
index 53d4753f..56a4d4c6 100644
--- a/enter.ml
+++ b/enter.ml
@@ -1083,6 +1083,7 @@ let rec main_action xs =
   | _ -> failwith "only one .cocci file allowed");
   Iteration.base_file_list := xs;
   previous_merges := ([], []);
+  let patching_failed = ref false in
   let rec toploop = function
       [] -> failwith "no C files provided"
     | x::xs ->
@@ -1366,6 +1367,7 @@ singleton lists are then just appended to each other during the merge. *)
 					    (Printexc.to_string e)
 					    all_cfiles;
 					  flush stderr;
+					  patching_failed := true;
 					  prev (* *)
 					end
 					else raise e) in
@@ -1414,6 +1416,10 @@ singleton lists are then just appended to each other during the merge. *)
 		  (x,xs,cocci_infos,outfiles)
 		end) in
       let (x,xs,cocci_infos,outfiles) = toploop xs in
+      if !patching_failed then begin
+        Printf.fprintf stderr "An error occurred when attempting to transform some files.\n";
+        raise (UnixExit (-1))
+      end;
       Common.profile_code "Main.result analysis" (fun () ->
 	Ctlcocci_integration.print_bench();
 	generate_outfiles outfiles x xs;
-- 
2.37.2


             reply	other threads:[~2022-09-04 22:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-04 22:50 Jan Tojnar [this message]
2022-09-05  7:57 ` [cocci] [PATCH] Exit with non-zero status when spatch on a directory fails Julia Lawall
2022-09-05  9:09   ` [cocci] [PATCH v2] " Jan Tojnar
2022-09-05 10:48     ` Julia Lawall
2022-09-05 12:04       ` Jan Tojnar
2022-09-05 12:29         ` Julia Lawall
     [not found]           ` <CAFGSp1umoczUe4npSesAUOLgSq=9VkvLUOV3x1hSvSajqQkGfw@mail.gmail.com>
2022-09-05 12:51             ` Julia Lawall
2022-09-05 14:18               ` Jan Tojnar
2022-09-05 16:03                 ` Julia Lawall
2022-09-05 19:51                 ` Julia Lawall
2022-09-05 20:21                   ` Jan Tojnar
2022-09-05 20:35                     ` Julia Lawall
2022-10-22 12:09                       ` Jan Tojnar
2022-10-22 12:26                         ` Julia Lawall
2022-09-05 21:28                     ` Julia Lawall

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=20220904225006.3438769-1-jtojnar@gmail.com \
    --to=jtojnar@gmail.com \
    --cc=cocci@inria.fr \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).