EngFlow / bazel_invocation_analyzer

A tool that automatically analyzes a Bazel build's profile and offers suggestions on how to make it faster.
https://analyzer.engflow.com
Apache License 2.0
90 stars 10 forks source link

[Core] Avoid NPEs on creating events #179

Closed saraadams closed 3 months ago

saraadams commented 3 months ago

When creating trace event format events, the code used to throw NullPointerExceptions when trying to construct an event from a JsonObject that was missing required members.

This change adds static fromJson methods, which check the members exist, or otherwise throw an IllegalArgumentException. This better communicates the kind of error that occurred - the provided Json did not have the expected form. This change also adds some basic documentation and tests for the Event classes.

saraadams commented 3 months ago

Could you please explain in the PR message why throwing IAE is better than NPE?

Done. Although throwing NPE vs IAE can also be seen as a matter of preference.