From 35b0ad901b51dbfeba3af987c68321cc902a6af5 Mon Sep 17 00:00:00 2001
From: Brandon Chinn <brandonchinn178@gmail.com>
Date: Sat, 17 Feb 2024 14:20:25 -0800
Subject: [PATCH] Fix searching for errors in sphinx build

---
 hadrian/src/Rules/Documentation.hs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hadrian/src/Rules/Documentation.hs b/hadrian/src/Rules/Documentation.hs
index 392d0d9f7ab0..3dc70ac83021 100644
--- a/hadrian/src/Rules/Documentation.hs
+++ b/hadrian/src/Rules/Documentation.hs
@@ -171,8 +171,14 @@ checkSphinxWarnings out = do
     when ("undefined label:" `isInfixOf` log)
       $ fail "Undefined labels found in Sphinx log."
 
-    when ("ERROR:" `isInfixOf` log)
+    when (any hasError (lines log))
       $ fail "Errors found in the Sphinx log."
+    where
+        hasError line =
+            case words line of
+                _ : "ERROR:" : _ -> True
+                _ : "CRITICAL:" : _ -> True
+                _ -> False
 
 -- | Check that all GHC flags are documented in the users guide.
 checkUserGuideFlags :: FilePath -> Action ()
-- 
GitLab