Hey folks. Is there any sort of reference class (o...
# problems-api
j
Hey folks. Is there any sort of reference class (or document) for the Problem spec? I understand that Problems is still incubating, but I'm interested in being able to serialize Problem data between processes (for example with JavaExec) so that the build can throw an exception using that data instead of just displaying a process exit code with the error(s) in stderr.
b
What do you need in particular? Examples of usage?
Keep in mind that we only have the HTML report so far, with console rendering coming soon
j
Mainly just details, so that they can be attached to the exception thrown by the build. But as much as possible is welcome.
b
So for your use case the Problems API might be just a bit too early.
j
Potentially? That would just be a starting point, I'm also using other aspects of it in plugins, such as file locations and especially solutions.
b
Mainly just details, so that they can be attached to the exception thrown by the build. But as much as possible is welcome.
Ah I see, there might be a misunderstanding here. Problems themselves are reported through a completely parallel piece of infrastructure. We have the ability to link together a problem with an exception (see ProblemReporter#throwing, but the association is in the Problems to Exception direction, not the other way around.
This might be not an issue for you, but might be important to know if you think about using it from external processes
j
Yes, that much I'm aware of, that's a primary use case of mine. But I want to be able to provide feedback to the developer when something goes wrong outside of the Gradle build like in a separate process execution. Hence, serializing Problems.
b
That’s fine, but you will need to take care of handling that conversation process
j
That works for me. I'm thinking it'd just be an internal file property where the file is empty if all went well, where I deserialize that file after process execution finishes.
b
That might work quite well, as we intend to report problems at the end of the build
👆 1
j
But it would be nice to have a reference spec class of Problems so I don't gotta write it all myself from scratch.
Or Problem, rather
b
reference spec class of Problems
Sorry, I don’t understand exactly what you are looking after. Are you looking for examples and/or real-world use-cases?
j
No no, I mean a literal class file or type that I could serialize to and deserialize from.
My bad
The idea is I'd use Gson or Groovy's JsonSlurper using that type, to share problem data like details and solutions.
What I don't want to do is make a Problem class in my tool, then deserialize it as Groovy's own Problem instance and just hope nothing changed in an update. So I'd use a library that I'd use in both my plugin and the external tool that contains a Problem type that they can both agree on.
b
Hmm, interesting, I don’t remember why we turned Problem into a marker interface. Regardless, considering the data available, DefaultProblem might be what you are looking after.
j
Yeah but I would really prefer not to rely on an internal type 😅
b
Yeah, exactly
That’s what I meant under you need to handle the conversation yourself, i.e., building your problem type, and then turn it into a Gradle problem by using the builder and reporting it.
j
Honestly if it's not out of scope, I would recommend making a small library with just the Problems API types to enable this kind of serialization.
b
We didn’t intend to use problems outside of Gradle’s scope in such a direct way
j
Fair enough
b
Honestly if it’s not out of scope, I would recommend making a small library with just the Problems API types to enable this kind of serialization.
Actually that’s good feedback
j
Hm, maybe just making a copy of DefaultProblems could be enough for now. But it would suck to do so for reasons discussed earlier.
Yeah no the library could just be 3 classes if you wanted. Or even just that one class. I just want it to exist.
b
We are a bit slow of the evolution of the Problems API right now, but I would consider this idea to extend the usability of it; but that’s unfortunately not going to happen tomorrow
j
I would not expect a project as massive as Gradle to apply my suggestion right this second 😛
😅 1
My hesitation with using DefaultProblems is not copying it to my tool, but rather deserializing to it in my plugin, because you could just move it somewhere else since it's in an internal package, let alone in an incubating API.
b
Can you explain your idea of usage a bit more in detail for me to understand what do you want to exactly do?
j
I want to create a JSON file of a problem that would be caught in my external tool (such as in a JavaExec) so that it can be deserialized in my plugin and used as a reported problem in the build. If I don't do this, the thrown exception is just the exit code without any additional data about what actually went wrong, where the user will have to check the console for details about the problem since it is all basically vomited in standard error output. IntelliJ IDEA does not help in this regard because when a build fails, the IDE's terminal will immediately focus on the reported problem (i.e. the exception thrown by the build), which initially hides the console log that would contain the actual problem. So what I want is to be able to process the problem in my plugin after the tool's execution and report it as a problem of the Gradle build so that it is enriched in the exception that caused the build to fail.
While I could make my own analyzer or problem spec, it would be far easier if I had an external library that contained the Problem type to serialize to in the tool and deserialize from in the plugin. And this is especially important since the Problem spec can still change, since the API is incubating.
b
Thanks! It’s a bit easier to understand this as a whole thing! I would suggest making an issue on gradle/gradle; I think this is a genuine feature request, and we should take a look at it with the wider team.
j
Works for me, I'll do that when I'm back home. Beautiful day outside for a walk while chatting on the Gradle Slack. 😁
b
Happy to hear! Have a nice day 🙂
party gradlephant 1
❤️ 1
cc. @Donát Csikós @Reinhold Degenfellner if you are interested in this conversation
j
I don't have a good way of titling the issue but I did my best and then included my description above in it. https://github.com/gradle/gradle/issues/35383