cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH] Exit with non-zero status when spatch on a directory fails
@ 2022-09-04 22:50 Jan Tojnar
  2022-09-05  7:57 ` Julia Lawall
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Tojnar @ 2022-09-04 22:50 UTC (permalink / raw)
  To: cocci; +Cc: Jan Tojnar

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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-10-22 12:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04 22:50 [cocci] [PATCH] Exit with non-zero status when spatch on a directory fails Jan Tojnar
2022-09-05  7:57 ` 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

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).