~jan0sch/smederee

Showing details for patch 237919b1f367386f3fca6fa97e0e71f01dd2ba38.
2024-06-10 (Mon), 11:24 AM - Jens Grassel - 237919b1f367386f3fca6fa97e0e71f01dd2ba38

VCS: Fix crash if repository contains no tags.

If a repository contains no tags the logic to show the last tag would crash.
This patch fixes this by checking the exitStatus of the darcs command before
passing the output onwards for further processing.

Fixes: b76d19787c2d510d587405467da872095e2abb76
Summary of changes
1 files modified with 8 lines added and 2 lines removed
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 8 added and 2 removed lines
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-01-11 15:00:59.346609344 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-01-11 15:00:59.346609344 +0000
@@ -472,8 +472,14 @@
                 )
             lastTag <- darcs
                 .log(directory.toNIO)(repositoryName.toString)(Chain(s"--from-tag=.", "--to-tag=.", "--xml-output"))
-                .map(log => scala.xml.XML.loadString(log.stdout.toList.mkString))
-                .map(xmlLog => (xmlLog \ "patch").flatMap(VcsRepositoryPatchMetadata.fromDarcsXmlLog).headOption)
+                .map(log =>
+                    if (log.exitValue === 0) {
+                        val xmlLog = scala.xml.XML.loadString(log.stdout.toList.mkString)
+                        (xmlLog \ "patch").flatMap(VcsRepositoryPatchMetadata.fromDarcsXmlLog).headOption
+                    } else {
+                        None
+                    }
+                )
             readmeData <- repo.traverse(repo => doLoadReadme(repo))
             readme <- readmeData match {
                 case Some((lines, Some(_), Some(renderableContent))) =>