Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make YamlError an Exception, makes for easier interop #300

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions core/shared/src/main/scala/org/virtuslab/yaml/YamlError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import org.virtuslab.yaml.internal.load.reader.token.TokenKind
/**
* An ADT representing a decoding failure.
*/
sealed trait YamlError {
def msg: String
}
sealed abstract class YamlError(val msg: String) extends Exception(msg)

final case class ParseError(msg: String) extends YamlError
final case class ParseError(override val msg: String) extends YamlError(msg)
object ParseError {
def from(expected: String, got: Token): ParseError = ParseError(
s"""|Expected
Expand All @@ -23,11 +21,11 @@ object ParseError {
def from(expected: TokenKind, got: Token): ParseError = ParseError.from(expected.toString, got)
}

final case class ComposerError(msg: String) extends YamlError
final case class ComposerError(override val msg: String) extends YamlError(msg)

final case class ModifyError(msg: String) extends YamlError
final case class ModifyError(override val msg: String) extends YamlError(msg)

final case class ConstructError(msg: String) extends YamlError
final case class ConstructError(override val msg: String) extends YamlError(msg)
object ConstructError {
private def from(
errorMsg: String,
Expand Down Expand Up @@ -65,7 +63,7 @@ object ConstructError {
def from(t: Throwable): ConstructError = from(t.getMessage, None, None)
}

final case class ScannerError(msg: String) extends Throwable with YamlError with NoStackTrace
final case class ScannerError(override val msg: String) extends YamlError(msg)
object ScannerError {
def from(obtained: String, got: Token): ScannerError = ScannerError(
s"""|Obtained
Expand Down