dangmai / prettier-plugin-apex

Code formatter for the Apex Programming Language
https://apex.dangmai.net
MIT License
256 stars 44 forks source link

Incomplete json returned from parseTextWithSpawn #695

Closed TalMat closed 2 years ago

TalMat commented 2 years ago

When executing on a .cls file, I've received Error: <partial json text>

This was not helpful, but did include a stack trace, and when poking around parseTextWithSpawn I noticed you're trying to check executionResult.error. It seems you are looking for executionResult.stderr, in this case. At least, that gave me a more-specific (java-related) error, so I figured I'd share that here. I do not know what the issue is in particular, from there.

executionResult.stderr.toString() at `/src/parser.js line 30 contains the follow error text:

`Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: No converter available ---- Debugging information ---- message : No converter available type : java.util.Optional converter : com.thoughtworks.xstream.converters.reflection.ReflectionConverter message[1] : Unable to make field private static final java.util.Optional java.util.Optional.EMPTY accessible: module java.base does not "opens java.util" to unnamed module @43df23d3

    at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:88)
    at com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:479)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:48)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:270)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:174)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:270)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:174)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:270)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:174)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:262)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1255)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1244)
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:1217)
    at net.dangmai.serializer.Apex.getAST(Apex.java:85)
    at net.dangmai.serializer.Apex.main(Apex.java:135)`
TalMat commented 2 years ago

Further info: This is using apex-ast-serializer.bat (windows machine) and the exit code is 1

The executionResult.stdout json text ends abruptly. It is not complete/well-formed, probably due to being interrupted by an xstream related error.

java -version is java version "19.0.1" 2022-10-18

dangmai commented 2 years ago

Hello, thank you for opening the bug report! This is new to me, and I think I need more info to debug this. Does this happen to one file, or does it happen to all files you're trying to format? Also, which Java distro are you using?

dangmai commented 2 years ago

Another question - which version of Prettier Apex are you running?

TalMat commented 2 years ago

I'm using the Oracle JRE installed from https://www.oracle.com/java/technologies/downloads/ (Java 19, Windows x64 MSI installer)

After creating a second .cls file to test, it appear it happens on a separate, single file as well. It also happens if there are multiple matched .cls files, though.

After updating from prettier-plugin-apex 1.8 to 1.11, the problem seems fixed. Thank you for such a prompt response, though. This formatting looks excellent!

dangmai commented 2 years ago

I'm glad it worked out! Support for Java >= 16 was only added in 1.9.0, so I should've asked that as the first question 😆