objectionary / eo

EOLANG, an Experimental Pure Object-Oriented Programming Language Based on 𝜑-calculus
https://www.eolang.org
MIT License
1.05k stars 133 forks source link

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

Open volodya-lombrozo opened 10 months ago

volodya-lombrozo commented 10 months ago

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 commented 10 months ago

@maxonfjvipon Could you take a look, please?

volodya-lombrozo commented 10 months ago

It's kinda urgent

maxonfjvipon commented 10 months ago

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

volodya-lombrozo commented 10 months ago

@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 commented 10 months ago

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

maxonfjvipon commented 10 months ago

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

volodya-lombrozo commented 10 months ago

@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 commented 10 months ago

@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 commented 10 months ago

@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 commented 10 months ago

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

volodya-lombrozo commented 10 months ago

@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 commented 10 months ago

@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 commented 10 months ago

@yegor256 We need adults here

yegor256 commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

Needs #2804

yegor256 commented 1 month ago

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

volodya-lombrozo commented 1 month ago

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

yegor256 commented 1 month ago

@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 commented 1 month ago

@yegor256 is it better now?