Skip to content

Commit

Permalink
Fix bad merge in YamlError
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect committed Jul 11, 2024
1 parent ebb3f2f commit 71c48da
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions core/shared/src/main/scala/org/virtuslab/yaml/YamlError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
}

0 comments on commit 71c48da

Please sign in to comment.