#2035 cli: fix exit code when a build is canceled
Merged 2 years ago by praiskup. Opened 2 years ago by schlupov.
copr/ schlupov/copr fix_exit_code  into  main

file modified
+12 -3
@@ -218,6 +218,7 @@ 

  

          prevstatus = defaultdict(lambda: None)

          failed_ids = []

+         canceled_ids = []

  

          watched = set(build_ids)

          done = set()
@@ -241,6 +242,8 @@ 

  

                      if build_details.state in ["failed"]:

                          failed_ids.append(build_id)

+                     if build_details.state in ["canceled"]:

+                         canceled_ids.append(build_id)

                      if build_details.state in ["succeeded", "skipped",

                                                 "failed", "canceled"]:

                          done.add(build_id)
@@ -253,10 +256,16 @@ 

  

                  time.sleep(30)

  

+             exception_message = ""

+             separator = ""

              if failed_ids:

-                 raise copr_exceptions.CoprBuildException(

-                     "Build(s) {0} failed.".format(

-                         ", ".join(str(x) for x in failed_ids)))

+                 exception_message = "Build(s) {0} failed.".format(", ".join(str(x) for x in failed_ids))

+                 separator = " "

+             if canceled_ids:

+                 exception_message += separator + "Build(s) {0} canceled.".format(", ".join(str(x) for x in canceled_ids))

+ 

+             if failed_ids or canceled_ids:

+                 raise copr_exceptions.CoprBuildException(exception_message)

  

          except KeyboardInterrupt:

              pass

file modified
+1 -1
@@ -789,7 +789,7 @@ 

      Also might happen when user interrupts the operation when they shouldn't.

  2 - Wrong arguments given.

  3 - Bad or no configuration.

- 4 - Build fails when Cli is waiting for the result.

+ 4 - Build failed or was canceled.

  5 - Communication error between Cli and server.

      This issue probably means bug and should be reported.

  

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

This is though a vector operation. There might be some succeded, some failed and some canceled builds. We should either return 1, or declare which builds failed and which were canceled.

From man copr,

1 - Bad request like wrong project name, insufficient rights etc.
4 - Build fails when Cli is waiting for the result.

I think we should return 4 instead?

These are ccanceled builds, not waiting (anymore?).

These are ccanceled builds, not waiting (anymore?).

Yes, just canceled.

rebased onto 153809a745f8089e60d62efeeef0fb7e35109dd4

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Metadata Update from @praiskup:
- Request assigned

2 years ago

There's a nit: The space between "failed" and "canceled" messages is fixed. WHen no canceled build exists, it is still printed.
I usually do this trick:

separator = ""
result_string = ""
if some_condition:
    result_string += separator + "Part 1"
    separator = " "
if some_other_condition:
    ....

I would just call it "exception_message".

I agree that exit status 4 is a correct value to return, but please fix the manual page.

I would by OK to ignore the PyLint "too many branches" issue for now, but the testsuite failure needs to be fixed.

rebased onto a3f3dd9

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Commit ea8388f fixes this pull-request

Pull-Request has been merged by praiskup

2 years ago