Skip to content

Commit 690483d

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

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

sjsonnet/src/sjsonnet/Evaluator.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,18 @@ 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(
690+
s"Field name must be string or null, not ${fieldName.prettyName}",
691+
pos
692+
)
693+
}
694+
692695
def visitMethod(rhs: Expr, params: Params, outerPos: Position)(implicit
693696
scope: ValScope): Val.Func =
694697
new Val.Func(outerPos, scope, params) {
@@ -856,11 +859,7 @@ class Evaluator(
856859
Error.fail(s"Duplicate key ${k} in evaluated object comprehension.", e.pos);
857860
}
858861
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-
)
862+
case x => fieldNameTypeError(x, e.pos)
864863
}
865864
}
866865
val valueCache = if (sup == null) {

0 commit comments

Comments
 (0)