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

ANTLR parsing error messages are not descriptive enough, in PhiMojo #3370

Open
volodya-lombrozo opened this issue Sep 13, 2024 · 18 comments
Open

Comments

@volodya-lombrozo
Copy link
Member

One of the integration tests in jeo-maven-plugin has the following pipeline:

bytecode -> (disassemble) xmir -> phi -> unphi -> xmir (assemble) -> bytecode.

First of all I generate App.xmir from App.class file (disassemble):

App.xmir.txt

Then I use eo:0.39.0:xmir-to-phi to generate App.phi:

App.phi.txt

Then I run eo:0.39.0:phi-to-xmir to generate App.xmir (and it is generated):

App.xmir.txt

However, during the eo:0.39.0:phi-to-xmir I get the following exception that fails the entire build:

1 files with parsing errors were found: [org/eolang/hone/App.phi]
Here is the full log
[INFO] --- eo:0.39.0:phi-to-xmir (phi-to-xmir) @ phi-unphi-it ---
line 23:12 token recognition error at: '@'
[INFO] 45 attributes loaded from 39 stream(s) in 9ms, 45 saved, 456 ignored: ["Archiver-Version", "Automatic-Module-Name", "Bnd-LastModified", "Build-Jdk", "Build-Jdk-Spec", "Built-By", "Bundle-ContactAddress", "Bundle-Description", "Bundle-DocURL", "Bundle-License", "Bundle-ManifestVersion", "Bundle-Name", "Bundle-RequiredExecutionEnvironment", "Bundle-SymbolicName", "Bundle-Vendor", "Bundle-Version", "Created-By", "EO-Dob", "EO-Revision", "EO-Version", "Export-Package", "Extension-Name", "Implementation-Build", "Implementation-Title", "Implementation-URL", "Implementation-Vendor", "Implementation-Vendor-Id", "Implementation-Version", "Import-Package", "Include-Resource", "JCabi-Build", "JCabi-Date", "JCabi-Version", "Main-Class", "Manifest-Version", "Multi-Release", "Originally-Created-By", "Project-Name", "Require-Capability", "Specification-Title", "Specification-Vendor", "Specification-Version", "Tool", "X-Compile-Source-JDK", "X-Compile-Target-JDK"]
[INFO] Parsed to xmir: /Users/lombrozo/Workspace/EOlang/jeo-maven-plugin/target/it/phi-unphi/target/generated-sources/eo-phi/org/eolang/hone/App.phi -> /Users/lombrozo/Workspace/EOlang/jeo-maven-plugin/target/it/phi-unphi/target/generated-sources/eo-unphi/org/eolang/hone/App.xmir
[INFO] Parsed 1 phi files to xmir
[ERROR] 1 files with parsing errors were found: [org/eolang/hone/App.phi]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.514 s
[INFO] Finished at: 2024-09-13T14:27:54+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eolang:eo-maven-plugin:0.39.0:phi-to-xmir (phi-to-xmir) on project phi-unphi-it: 'org.eolang.maven.UnphiMojo@5e80d5' execution failed: java.lang.IllegalStateException: 1 files with parsing errors were found: [org/eolang/hone/App.phi] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eolang:eo-maven-plugin:0.39.0:phi-to-xmir (phi-to-xmir) on project phi-unphi-it: 'org.eolang.maven.UnphiMojo@5e80d5' execution failed
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:904)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:204)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: org.apache.maven.plugin.MojoFailureException: 'org.eolang.maven.UnphiMojo@5e80d5' execution failed
    at org.eolang.maven.SafeMojo.exitError (SafeMojo.java:391)
    at org.eolang.maven.SafeMojo.execute (SafeMojo.java:292)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:904)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:204)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: 1 files with parsing errors were found: [org/eolang/hone/App.phi]
    at java.util.concurrent.FutureTask.report (FutureTask.java:122)
    at java.util.concurrent.FutureTask.get (FutureTask.java:205)
    at org.eolang.maven.SafeMojo.execWithTimeout (SafeMojo.java:340)
    at org.eolang.maven.SafeMojo.execute (SafeMojo.java:274)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:904)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:281)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:204)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: java.lang.IllegalStateException: 1 files with parsing errors were found: [org/eolang/hone/App.phi]
    at org.eolang.maven.UnphiMojo.exec (UnphiMojo.java:147)
    at org.eolang.maven.SafeMojo.lambda$execWithTimeout$4 (SafeMojo.java:337)
    at java.util.concurrent.FutureTask.run (FutureTask.java:317)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
    at java.lang.Thread.run (Thread.java:1583)
@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Could you take a look, please? It's kinda urgent.

@maxonfjvipon
Copy link
Member

@volodya-lombrozo the name @init@-KClW is invalid and not supported by phi grammar. The name has to start with simple english letter

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Why doesn't xmir-to-phi say anything about it? I believe it's a bug either in xmir-to-phi, or phi-to-xmir must accept @init@-KClW.
Moreover, the exception message 1 files with parsing errors were found: [org/eolang/hone/App.phi] doesn't say anything about @init@-KClW naming, which is frustrating and consumes lots of time to investigate the problem. We would be able to avoid this discussion, if we had informative messages.

@maxonfjvipon
Copy link
Member

@volodya-lombrozo it said here (from you log)
image

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Missed that, thank you! However, it's still rather cryptic and not very obvious. As I understand, it's a default lexer message. Is it possible to add context to this message?
https://www.yegor256.com/2015/12/01/rethrow-exceptions.html

As for the the rest:

I believe it's a bug either in xmir-to-phi, or phi-to-xmir must accept @init@-KClW.

It's still important and blocks other issues.

@maxonfjvipon
Copy link
Member

@volodya-lombrozo according to phi paper:
image

"attribute is ... an english letters starting with a lowercase letter"

@maxonfjvipon
Copy link
Member

@yegor256 WDYT? Should we add an ability to parse such names @init@-KClW in phi grammar?

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Could you add this check to the xmir-to-phi or allow such names, please?

Note: The problem happens on xmir-to-phi <-> phi-to-xmir side ONLY in eo-maven-plugin . jeo:disassemble and jeo:assemble have nothing to do with this.

@yegor256
Copy link
Member

yegor256 commented Sep 13, 2024

@maxonfjvipon no, we should not allow such names in phi grammar (we should reject them both at xmir-to-phi and in phi-to-xmir)

@maxonfjvipon
Copy link
Member

@volodya-lombrozo this "check" is enabled by grammar itself, it just fails on parsing step

@volodya-lombrozo
Copy link
Member Author

@yegor256 What about the following names:

a@init@
a-init-a
a------

?

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon

@volodya-lombrozo this "check" is enabled by grammar itself, it just fails on parsing step

Anyway, it is still a relevant question:

However, it's still rather cryptic and not very obvious. As I understand, it's a default lexer message. Is it possible to add context to this message?
https://www.yegor256.com/2015/12/01/rethrow-exceptions.html

@yegor256
Copy link
Member

@volodya-lombrozo any name is fine, as long as it starts with [a-z] and doesn't contain spaces and EOLs. @maxonfjvipon please, correct me if I'm wrong

@maxonfjvipon
Copy link
Member

@yegor256 you're right

@yegor256
Copy link
Member

@volodya-lombrozo still a bug?

@volodya-lombrozo
Copy link
Member Author

@maxonfjvipon Did you add any checks before the xmir-to-phi goal?

@maxonfjvipon
Copy link
Member

@volodya-lombrozo I didn't.
@yegor256 we should think about a general mechanism of interpretation ANTLR error messages to some human readable ones, so the end-user is not guessing what went wrong but seeing a bug immediately

@yegor256
Copy link
Member

@maxonfjvipon how about we try to use paraphrase from ANTLR: https://stackoverflow.com/a/2266574/187141

@yegor256 yegor256 changed the title PhiMojo generates PHI expressions with parsing errors ANTLR parsing error messages are not descriptive enough, in PhiMojo Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants