Giter Site home page Giter Site logo

Comments (10)

Pante avatar Pante commented on July 19, 2024

If I understand correctly you tried to feed the extension source code which contained compilation errors. In that case, I think JavacExtension will be more appropriate. See the javac extension.

Due to how ToolExtension works internally, I don't think it's possible for it to parse uncompilable code.

from elementary.

toolforger avatar toolforger commented on July 19, 2024

It's just the annotation processor that throws errors, javac can parse if no problems.

To the very least, the error message shouldn't say "could not start the java compiler", that's just misleading: The Java compiler started, spat out error messages, terminated normally, and ToolsExtension even constructs a Results object.

from elementary.

toolforger avatar toolforger commented on July 19, 2024

But yeah I see what you mean; expecting javac to return an AST in case of errors, whether from an annotation processor or not, is likely going beyond what the TCK demands.

from elementary.

Pante avatar Pante commented on July 19, 2024

Could attach a short snippet of code that demonstrates this?

It seems strange that DaemonCompiler includes an annotation processor when running. I think what may be happening is that DaemonCompiler is unintentionally picking up the annotation processor on the classpath.

I can't think of how it might otherwise compile while including the annotation processor under test.

On another note, if an annotation processor does throw an exception, it does mean that compilation has failed since it is assumed that the annotation processor has errored out unintentionally. For expected errors, i.e. annotation processor expected some other type, it should log a failure using the given Messager instead.

from elementary.

toolforger avatar toolforger commented on July 19, 2024

Nah, it's the example project that's erroring out.
The compiler messages also have just the annotation processor's error message.

Example project is at https://github.com/toolforger/elementary-demo .
I put a breakpoint in DaemonCompiler.run(), on the if (!results.success) { line, so it was easy to check the logs and see what actually happened.

from elementary.

toolforger avatar toolforger commented on July 19, 2024

On a tangent, I think I can work around the issue with erroring-out annotation processor - just leave out the annotations, make the tests not check that the annotation processor errors out but just that the conditions hold that will make it error out, in those code snippets that we believe should trigger specific error conditions.
Still, the error message is misleading. I think it's this code that needs a bit of a rewrite:

        try {
            var results = compiler.compile(files);
            if (!results.success) {
                throw new CompilationException(results.find().diagnostics());
            }
            
        } catch (Throwable e) {
            processor.environment.completeExceptionally(new CompilationException("Failed to start javac", e));
        }

I think it should be something like this:

        Results results;
        try {
            var results = compiler.compile(files);
        } catch (Throwable e) {
            processor.environment.completeExceptionally(new CompilationException("javac did not start, or crashed", e));
            return;
        }
        if (!results.success) {
            processor.environment.completeExceptionally(new CompilationException(results.find().diagnostics()));
        }

This also avoids wrapping a CompilationException in another CompilationException, so the exception stack trace will have a better noise-to-signal ratio.
I wanted to insert a "javac completed with error messages:" line before the results.find().diagnostics() messages, but it would have complicated the suggested code so I left it out for better clarity.

from elementary.

Pante avatar Pante commented on July 19, 2024

I think I get what you mean, but can't the if-statement be placed in the try-block? Also, any chance you would be willing to submit a PR for this on master heh?

EDIT: Okay I think I derped up here, the throw should definitely be outside.

from elementary.

toolforger avatar toolforger commented on July 19, 2024

I have found over the years that nesting tends to couple code blocks, which can hinder refactoring. It also creates a bias towards keeping the code path joined, even if it shouldn't be.
The exact decision is pretty subjective though, so I don't care much about the exact flow.

The subjectivity is also why I didn't create a PR: I don't know what your priorities are, so any PR would probably be rejected and require more work from both of us.

from elementary.

Pante avatar Pante commented on July 19, 2024

Fair enough, I'll create a PR later then, thanks for reporting this issue regardless!

from elementary.

Pante avatar Pante commented on July 19, 2024

Fixed in b320fd0

from elementary.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.