diff --git a/upickle/src/upickle/Api.scala b/upickle/src/upickle/Api.scala index 4c461d6ce..5a39bb1a2 100644 --- a/upickle/src/upickle/Api.scala +++ b/upickle/src/upickle/Api.scala @@ -274,11 +274,14 @@ trait AttributeTagged extends Api with Annotator{ } } def visitEnd(index: Int) = { - if (context == null) throw new Abort("expected tagged dictionary") + def missingKeyMsg = s"""Missing key "$tagName" for tagged dictionary""" + if (context == null) throw new Abort(missingKeyMsg) else if (fastPath) context.visitEnd(index).asInstanceOf[T] else{ val x = context.visitEnd(index).asInstanceOf[IndexedValue.Obj] - val keyAttr = x.value0.find(_._1.toString == tagName).get._2 + val keyAttr = x.value0.find(_._1.toString == tagName) + .getOrElse(throw new Abort(missingKeyMsg)) + ._2 val key = keyAttr.asInstanceOf[IndexedValue.Str].value0.toString val delegate = taggedReader.findReader(key) if (delegate == null){ diff --git a/upickle/test/src/upickle/FailureTests.scala b/upickle/test/src/upickle/FailureTests.scala index 4ccd5bc84..2f915891f 100644 --- a/upickle/test/src/upickle/FailureTests.scala +++ b/upickle/test/src/upickle/FailureTests.scala @@ -227,7 +227,8 @@ object FailureTests extends TestSuite { test - assertErrorMsgDefault[Fi.Fo]("""{"$type": "omg"}""", "invalid tag for tagged object: omg at index 1") test - assertErrorMsgDefault[Fi](""""omg"""", "invalid tag for tagged object: omg at index 0") test - assertErrorMsgDefault[Fi]("""{"$type": "omg"}""", "invalid tag for tagged object: omg at index 1") - test - assertErrorMsgDefault[Fi]("""{}""", "expected tagged dictionary") + test - assertErrorMsgDefault[Fi]("""{}""", """Missing key "$type" for tagged dictionary at index 1""") + test - assertErrorMsgDefault[Fi]("""{"mispelledTypeTag": "omg"}""", """Missing key "$type" for tagged dictionary at index 26""") } test("taggedInvalidBody"){