diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 77b69b876c35e8199ad90f5f57406316a50b21f2..4709bd6d549359626411fa2016a9c7bb47c8ff3d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -85,12 +85,16 @@ Check style:
     - |
       # pre-commit run --all-files
       pre-commit run --color=always --all-files || {
-        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}"
-        test -s "${STYLE_PATCH}" && {
-          printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
+        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}" && {
+          test -s "${STYLE_PATCH}" && {
+            printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
         ${CI_JOB_URL}/artifacts/raw/${STYLE_PATCH}.\n${DEFAULT}"
+          } || {
+            printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+            rm -f "${STYLE_PATCH}"
+          }
         } || {
-          printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+          printf "${RED}Failed to generate a patch file.\n${DEFAULT}"
           rm -f "${STYLE_PATCH}"
         }
         printf "${RED}You can reproduce this check locally with \`pre-commit run --all-files\`.