Skip to content

Commit bd4e1b2

Browse files
committed
DRY up the error message.
1 parent cb5593e commit bd4e1b2

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

sjsonnet/src/sjsonnet/Evaluator.scala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,15 @@ class Evaluator(
680680
visitExpr(k) match {
681681
case Val.Str(_, k1) => k1
682682
case Val.Null(_) => null
683-
case x =>
684-
Error.fail(
685-
s"Field name must be string or null, not ${x.prettyName}",
686-
pos
687-
)
683+
case x => fieldNameTypeError(x, pos)
688684
}
689685
}
690686
}
691687

688+
private def fieldNameTypeError(fieldName: Val, pos: Position): Nothing = {
689+
Error.fail(s"Field name must be string or null, not ${fieldName.prettyName}", pos)
690+
}
691+
692692
def visitMethod(rhs: Expr, params: Params, outerPos: Position)(implicit
693693
scope: ValScope): Val.Func =
694694
new Val.Func(outerPos, scope, params) {
@@ -856,11 +856,7 @@ class Evaluator(
856856
Error.fail(s"Duplicate key ${k} in evaluated object comprehension.", e.pos);
857857
}
858858
case Val.Null(_) => // do nothing
859-
case x =>
860-
Error.fail(
861-
s"Field name must be string or null, not ${x.prettyName}",
862-
e.pos
863-
)
859+
case x => fieldNameTypeError(x, e.pos)
864860
}
865861
}
866862
val valueCache = if (sup == null) {

0 commit comments

Comments
 (0)