-
Notifications
You must be signed in to change notification settings - Fork 155
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
Normalize node paths in errors #229
Conversation
5fd8d4a
to
7a93288
Compare
7a93288
to
3a4a0e3
Compare
3a4a0e3
to
f5a0850
Compare
f5a0850
to
d3924d2
Compare
d3924d2
to
16169a3
Compare
16169a3
to
efc3074
Compare
@GreyCat, @generalmimon, I see that you have some activity in the project recently. Could you find a time to review my PRs, for example, this? |
48ff6a9
to
75649e5
Compare
getValueStr, getOptValueStr and getValueIdentifier (which is uses getOptValueStr) all does this for their own errors therefore this is just a unification of behavior This change requires corresponding change in kaitai_struct_tests repository Partially fixes the following error (the first line): ``` [info] - switch_on_malformed *** FAILED *** [info] switch_on_malformed.ksy: /seq/0: [info] error: parsing expression '42/' failed on 1:3, expected Expected end-of-input:1:3, found "/" [info] did not equal switch_on_malformed.ksy: /seq/0/switch-on: [info] error: parsing expression '42/' failed on 1:3, expected "or" | CharsWhile(Set( , n)) | "\\\n" | End (SimpleMatchers.scala:34) ```
This change requires corresponding change in kaitai_struct_tests repository
TypeValidator.validateSwitchType uses path with "type" therefore this is just behavior unification This change requires corresponding change in kaitai_struct_tests repository
… type/enum" errors This change requires corresponding change in kaitai_struct_tests repository
This change requires corresponding change in kaitai_struct_tests repository Partially fixes the following error (the first line): ``` [info] - attr_invalid_switch_inner *** FAILED *** [info] attr_invalid_switch_inner.ksy: /seq/1/type/cases/IntNum(42)/size: [info] error: invalid type: expected integer, got CalcBooleanType [info] [info] attr_invalid_switch_inner.ksy: /seq/1/type/cases/Name(identifier(_))/size: [info] error: invalid type: expected integer, got CalcBooleanType [info] did not equal attr_invalid_switch_inner.ksy: /seq/1/size: [info] error: invalid type: expected integer, got CalcBooleanType (SimpleMatchers.scala:34) ```
75649e5
to
4235425
Compare
…ould not be located Also all other error messages starts with lower case, so adjust that's too Fixes the test: ``` [info] - meta_imports_abs_unknown *** FAILED *** [info] meta_imports_abs_unknown: /meta/imports/0: [info] error: Unable to find 'unknown_absolute_name' in import search paths, using: List() [info] did not equal meta_imports_abs_unknown.ksy: /meta/imports/0: [info] error: Unable to find 'unknown_absolute_name' in import search paths, using: List() (SimpleMatchers.scala:34) ```
4235425
to
bb717cb
Compare
Merging this one as well! Thanks so much for cleaning this up and being persistent with all these rebasing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accidentally left this comment "pending" the whole time and forgot about it, so I'm at least posting it now.
@@ -167,13 +167,13 @@ object AttrSpec { | |||
fromYaml2(srcMap, path, metaDef, id) | |||
} catch { | |||
case (epe: Expressions.ParseException) => | |||
throw KSYParseError.expression(epe, path) | |||
throw KSYParseError.expression(epe, path ++ List("type")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skeptical that only the type
key is always the culprit of ParseException
because fromYaml2
method processes a lot of keys inside.
Upon further inspection, these should be the calls that may emit Expressions.ParseException
:
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/AttrSpec.scala
Line 190 in 3a4a0e3
val valid = srcMap.get("valid").map(ValidationSpec.fromYaml(_, path ++ List("valid"))) |
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/AttrSpec.scala
Lines 214 to 216 in 3a4a0e3
DataType.fromYaml( | |
None, path, metaDef, yamlAttrArgs | |
) |
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/AttrSpec.scala
Lines 220 to 222 in 3a4a0e3
DataType.fromYaml( | |
Some(simpleType), path, metaDef, yamlAttrArgs | |
) |
But even if it's always the type
key, exceptions should be definitely handled closer to where they arise. Quite a few keys processed in fromYaml2
need to parse expressions, but they normally catch it right away (as they should), e.g.:
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/ProcessExpr.scala
Lines 39 to 42 in 8913518
} catch { | |
case epe: Expressions.ParseException => | |
throw KSYParseError.expression(epe, path) | |
} |
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/AttrSpec.scala
Line 179 in 3a4a0e3
val size = ParseUtils.getOptValueExpression(srcMap, "size", path) kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/ParseUtils.scala
Lines 97 to 104 in 3a4a0e3
def getOptValueExpression(src: Map[String, Any], field: String, path: List[String]): Option[Ast.expr] = { try { getOptValueStr(src, field, path).map(Expressions.parse) } catch { case epe: Expressions.ParseException => throw KSYParseError.expression(epe, path ++ List(field)) } }
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/format/AttrSpec.scala
Lines 291 to 296 in 3a4a0e3
try { | |
Expressions.parse(condition) -> condType | |
} catch { | |
case epe: Expressions.ParseException => | |
throw KSYParseError.expression(epe, casePath) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skeptical that only the
type
key is always the culprit ofParseException
becausefromYaml2
method processes a lot of keys inside.
That does not matter. You already inside type
key here, and all other keys that fromYaml2
processes here are subkeys of a type
.
After this change all paths in errors will point to existing nodes in KSY file and node, where error is originated
This PR introduces 10 new failures (76 vs 66) because it changes error messages which is it purpose. So, this PR should be merged together with kaitai-io/kaitai_struct_tests#92 which is fixes test data accordingly.