From 71c48dac0cc6ea1afef8877d0ca923e8d9155d21 Mon Sep 17 00:00:00 2001 From: Ondra Pelech Date: Thu, 11 Jul 2024 15:36:48 +0200 Subject: [PATCH] Fix bad merge in YamlError --- .../scala/org/virtuslab/yaml/YamlError.scala | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/core/shared/src/main/scala/org/virtuslab/yaml/YamlError.scala b/core/shared/src/main/scala/org/virtuslab/yaml/YamlError.scala index 86d267daf..b35cca165 100644 --- a/core/shared/src/main/scala/org/virtuslab/yaml/YamlError.scala +++ b/core/shared/src/main/scala/org/virtuslab/yaml/YamlError.scala @@ -10,47 +10,45 @@ import org.virtuslab.yaml.internal.load.TagValue /** * An ADT representing a decoding failure. */ -sealed trait YamlError { - def msg: String -} +sealed abstract class YamlError(val msg: String) extends Exception(msg) -sealed trait ParseError extends YamlError +sealed abstract class ParseError(override val msg: String) extends YamlError(msg) object ParseError { def from(expected: String, got: Token): ParseError = ExpectedTokenKind(expected, got) def from(expected: TokenKind, got: Token): ParseError = ParseError.from(expected.toString, got) - final case class ExpectedTokenKind(expected: String, got: Token) extends ParseError { - def msg: String = - s"""|Expected - |$expected but instead got ${got.kind} - |${got.range.errorMsg}""".stripMargin - } + final case class ExpectedTokenKind(expected: String, got: Token) + extends ParseError( + s"""|Expected + |$expected but instead got ${got.kind} + |${got.range.errorMsg}""".stripMargin + ) - final case class NoRegisteredTagDirective(handleKey: String, tokenTag: Token) extends ParseError { - def msg: String = s"There is no registered tag directive for handle $handleKey" - } + final case class NoRegisteredTagDirective(handleKey: String, tokenTag: Token) + extends ParseError( + s"There is no registered tag directive for handle $handleKey" + ) } -final case class ComposerError(override val msg: String) extends YamlError +final case class ComposerError(override val msg: String) extends YamlError(msg) -final case class ModifyError(override val msg: String) extends YamlError +final case class ModifyError(override val msg: String) extends YamlError(msg) final case class ConstructError( errorMsg: String, node: Option[Node], expected: Option[String] -) extends YamlError { - def msg: String = node.flatMap(_.pos) match { - case Some(range) => - s"""|$errorMsg - |at ${range.start.line}:${range.start.column},${expected - .map(exp => s" expected $exp") - .getOrElse("")} - |${range.errorMsg} """.stripMargin - case None => - errorMsg - } -} +) extends YamlError(node.flatMap(_.pos) match { + case Some(range) => + s"""|$errorMsg + |at ${range.start.line}:${range.start.column},${expected + .map(exp => s" expected $exp") + .getOrElse("")} + |${range.errorMsg} """.stripMargin + case None => + errorMsg + + }) object ConstructError { private def from( errorMsg: String, @@ -76,24 +74,26 @@ object ConstructError { def from(t: Throwable): ConstructError = from(t.getMessage, None, None) } -sealed trait ScannerError extends Throwable with YamlError with NoStackTrace +sealed abstract class ScannerError(override val msg: String) + extends YamlError(msg) + with NoStackTrace object ScannerError { def from(obtained: String, got: Token): ScannerError = Obtained(obtained, got) def from(range: Range, msg: String): ScannerError = AtRange(range, msg) - case class Obtained(obtained: String, got: Token) extends ScannerError { - def msg: String = - s"""|Obtained - |$obtained but expected got ${got.kind} - |${got.range.errorMsg}""".stripMargin - } + case class Obtained(obtained: String, got: Token) + extends ScannerError( + s"""|Obtained + |$obtained but expected got ${got.kind} + |${got.range.errorMsg}""".stripMargin + ) - case class AtRange(range: Range, rawMsg: String) extends ScannerError { - def msg: String = - s"""|Error at line ${range.start.line}, column ${range.start.column}: - |${range.errorMsg} - |$msg - |""".stripMargin - } + case class AtRange(range: Range, rawMsg: String) + extends ScannerError( + s"""|Error at line ${range.start.line}, column ${range.start.column}: + |${range.errorMsg} + |$rawMsg + |""".stripMargin + ) }