Skip to content
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

The translation from XMIR to EO throws misleading error messages #2801

Open
volodya-lombrozo opened this issue Jan 18, 2024 · 20 comments
Open
Assignees
Labels
Milestone

Comments

@volodya-lombrozo
Copy link
Member

I'm trying to print eo by using the following command new Xmir.Default(new XMLDocument(xml)).toEO(), and it gives me the following error:

[main] ERROR com.jcabi.xml.ConsoleErrorListener -- #fatalError(): org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.; SystemID: file:///org/eolang/parser/xmir-to-eo.xsl; Line#: 109; Column#: 61

The full stacktrace:

java.lang.IllegalArgumentException: Failed to transform by net.sf.saxon.jaxp.TransformerImpl: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.; SystemID: file:///org/eolang/parser/xmir-to-eo.xsl; Line#: 109; Column#: 61

	at com.jcabi.xml.XSLDocument.transformInto(XSLDocument.java:468)
	at com.jcabi.xml.XSLDocument.transform(XSLDocument.java:420)
	at com.yegor256.xsline.StXSL.lambda$new$1(StXSL.java:45)
	at com.yegor256.xsline.StLambda.apply(StLambda.java:115)
	at com.yegor256.xsline.StEnvelope.apply(StEnvelope.java:61)
	at com.yegor256.xsline.StEnvelope.apply(StEnvelope.java:61)
	at com.yegor256.xsline.Xsline.pass(Xsline.java:85)
	at org.eolang.parser.xmir.Xmir$Default.toEO(Xmir.java:108)
	at org.eolang.opeo.decompilation.DecompilerMachineTest.decompilesFieldAccessAndMethodInvocationToEo(DecompilerMachineTest.java:287)
	at java.base/java.lang.reflect.Method.invoke(Method.java:578)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: net.sf.saxon.trans.XPathException: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
	at net.sf.saxon.dom.DOMWriter.characters(DOMWriter.java:234)
	at net.sf.saxon.event.ProxyReceiver.characters(ProxyReceiver.java:158)
	at net.sf.saxon.event.SequenceNormalizer.characters(SequenceNormalizer.java:99)
	at net.sf.saxon.event.RegularSequenceChecker.characters(RegularSequenceChecker.java:182)
	at net.sf.saxon.event.ComplexContentOutputter.characters(ComplexContentOutputter.java:275)
	at net.sf.saxon.expr.instruct.ValueOf$TextNodeOutputStreamer.append(ValueOf.java:467)
	at net.sf.saxon.expr.Literal$LiteralElaborator.lambda$elaborateForPush$1(Literal.java:882)
	at net.sf.saxon.expr.instruct.ValueOf$ValueOfElaborator.lambda$elaborateForPush$1(ValueOf.java:420)
	at net.sf.saxon.expr.instruct.Choose$ChooseExprElaborator.lambda$elaborateForPush$11(Choose.java:1173)
	at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:376)
	at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:587)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:521)
	at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesElaborator.lambda$elaborateForPush$1(ApplyTemplates.java:650)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$4(Block.java:895)
	at net.sf.saxon.expr.instruct.Choose$ChooseExprElaborator.lambda$elaborateForPush$11(Choose.java:1174)
	at net.sf.saxon.expr.instruct.Block$BlockElaborator.lambda$elaborateForPush$1(Block.java:853)
	at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:376)
	at net.sf.saxon.trans.Mode.handleRuleNotNull(Mode.java:587)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:521)
	at net.sf.saxon.trans.rules.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:72)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:518)
	at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:684)
	at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:430)
	at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:358)
	at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:75)
	at com.jcabi.xml.XSLDocument.transformInto(XSLDocument.java:458)
	... 11 more
Caused by: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
	at java.xml/com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:359)
	at java.xml/com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(ParentNode.java:286)
	at java.xml/com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:447)
	at java.xml/com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:230)
	at net.sf.saxon.dom.DOMWriter.characters(DOMWriter.java:231)
	... 36 more

I don't know what to do with it and how to fix my xmir. Could you please add more human-readable message?

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Could you take a look, please?

@volodya-lombrozo
Copy link
Member Author

It's kinda urgent

@maxonfjvipon
Copy link
Member

@volodya-lombrozo could you please provide an xmir you try to print?

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Jan 18, 2024

@maxonfjvipon

<o base="opcode" line="999" name="LDC-1">
  <o base="int" data="bytes">00 00 00 00 00 00 00 12</o>
  <o base="string" data="bytes">62 79 65</o>
</o>

Here the entire java code, text variable is above:

final String text = new Xembler(this.toXmir(), new Transformers.Node()).xmlQuietly();
System.out.println(text);
return new Xmir.Default(new XMLDocument(text)).toEO();

@volodya-lombrozo
Copy link
Member Author

Same for <o base="opcode" line="999" name="LDC-1"/>, <o base="opcode" line="999" name="LDC"/>, <o/>

@maxonfjvipon
Copy link
Member

@volodya-lombrozo your examples are not valid. There's no <program> and <objects> nodes

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon, could you also ensure their validity, please? At least, they used to be valid with the old 'XMIR' implementation, and I don't see any reason why they wouldn't be valid. Moreover, it's strange that you check validity during printing eo. As a developer I don't expect it.

@maxonfjvipon
Copy link
Member

maxonfjvipon commented Jan 18, 2024

@volodya-lombrozo old XMIR implementation was wrong. It tried to print whatever XML you provide to it. XMIR as a format has a certain structure - XSD schema (Schema object from eo-maven-plugin). So Xmir.Default objects expects that incoming XML is XMIR, but not a random XML with <o> nodes.

@maxonfjvipon
Copy link
Member

@volodya-lombrozo I could add validation to Xmir.Default object but I believe it would make you more troubles and we already have such validation in PrintMojo that uses Xmir

@maxonfjvipon
Copy link
Member

@volodya-lombrozo And I think we definitely need to add some human readable message if something is wrong

@volodya-lombrozo
Copy link
Member Author

volodya-lombrozo commented Jan 18, 2024

@maxonfjvipon What if I need to print only part of the eo (a single object for instance?) It's strange that now I need to create the entire xmir structure to do it (which in turn complicates testing in my case.)

@volodya-lombrozo
Copy link
Member Author

@volodya-lombrozo I could add validation to Xmir.Default object but I believe it would make you more troubles and we already have such validation in PrintMojo that uses Xmir

I believe it's better to remove the validation here. Or give a chance to use some other class without validation.

@maxonfjvipon
Copy link
Member

@yegor256 We need adults here

@yegor256
Copy link
Member

@volodya-lombrozo I'm on the XSD side here: XMIR is a data format that has certain limitations, for example it starts with <program> and keeps all <o> objects inside the <objects> element. Let's adhere to this format, to make sure we don't have false expectations about the behavior of different components of our environment. So, if it's XMIR it should be XSD-compliant. BTW, it's not so hard to achieve.

@volodya-lombrozo
Copy link
Member Author

Ok. Anyway, I believe Xmir.Default#toEO should print human-readable message instead of:

[main] ERROR com.jcabi.xml.ConsoleErrorListener -- #fatalError(): org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.; SystemID: file:///org/eolang/parser/xmir-to-eo.xsl; Line#: 109; Column#: 61

@maxonfjvipon
Copy link
Member

Needs #2804

@maxonfjvipon maxonfjvipon added this to the Important milestone Feb 2, 2024
@yegor256
Copy link
Member

@volodya-lombrozo seems to be a duplicate of #3370?

@volodya-lombrozo
Copy link
Member Author

@yegor256 #3370 issue is related to the PHI printing. This issue is related to EO printing.

@volodya-lombrozo volodya-lombrozo changed the title Human-readable error description XMIR to EO: Human-readable error description Oct 14, 2024
@yegor256
Copy link
Member

@volodya-lombrozo usually, it's better to give titles to tickets such that they (the titles) explain the entire problem. A reader should understand what's wrong and what needs to be fixed. Here, I would use a title like "error messages are misleading" or "better error messages are needed" (you can make up a better one, but it has to explain what's wrong)

@volodya-lombrozo volodya-lombrozo changed the title XMIR to EO: Human-readable error description The translation from XMIR to EO throws misleading error messages Oct 14, 2024
@volodya-lombrozo
Copy link
Member Author

@yegor256 is it better now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants