summaryrefslogtreecommitdiff
path: root/crashboxd/src/main/scala/io/crashbox/ci/yaml/YamlReader.scala
blob: f486676c878a5bb39c78926bfc177c2f15dadb95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package io.crashbox.ci
package yaml

trait YamlReader[A] {

  def read(yml: YamlValue): A

  protected def formatError(found: YamlValue, required: String) = {
    val foundType = found match {
      case _: YamlString => "string"
      case _: YamlSeq => "sequence"
      case _: YamlMap => "mapping"
    }

    throw new YamlFormatException(
      s"$found is of type $foundType, required: $required"
    )
  }

  protected def readError(node: YamlValue, msg: String) = {
    throw new YamlFormatException(node.toString + ": " + msg)
  }

}