Skip to content

Commit 993869b

Browse files
committed
Improve error messaging in sidebar YAML parser
1 parent bcaa1ca commit 993869b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.`type`.TypeReference;
77
import scala.jdk.CollectionConverters._
88
import java.util.Optional
99
import scala.beans._
10+
import java.nio.file.{Files, Paths}
1011

1112
enum Sidebar:
1213
case Category(
@@ -32,11 +33,22 @@ object Sidebar:
3233

3334
private def toSidebar(r: RawInput)(using CompilerContext): Sidebar = r match
3435
case RawInput(title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
36+
val basePath = Paths.get("docs/_docs")
37+
val pagePath = basePath.resolve(page)
38+
if !Files.exists(pagePath) then
39+
report.error(s"Page $page does not exist.")
3540
Sidebar.Page(Option.when(title.nonEmpty)(title), page, hidden)
3641
case RawInput(title, page, index, subsection, dir, hidden) if page.isEmpty && (!subsection.isEmpty() || !index.isEmpty()) =>
3742
Sidebar.Category(Option.when(title.nonEmpty)(title), Option.when(index.nonEmpty)(index), subsection.asScala.map(toSidebar).toList, Option.when(dir.nonEmpty)(dir))
3843
case RawInput(title, page, index, subsection, dir, hidden) =>
39-
report.error(s"Error parsing YAML configuration file.\n$schemaMessage")
44+
val errors = (title.isEmpty(), page.isEmpty(), index.isEmpty(), subsection.isEmpty(), dir.isEmpty())
45+
println(errors)
46+
errors match
47+
case (true, _, _, _, _) =>
48+
report.error(s"Title is not provided.\n$schemaMessage")
49+
case (false, true, true, _, _) =>
50+
report.error(s"Index or page path to at least one page is missing.\n$schemaMessage")
51+
case _ => report.error(s"Error parsing YAML configuration file.\n$schemaMessage")
4052
Sidebar.Page(None, page, hidden)
4153

4254
private def schemaMessage: String =

0 commit comments

Comments
 (0)