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

[maven-extension] Emit a warning rather than failing the build with an exception on illegal state #776

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public final class SpanRegistry {
*/
public void setRootSpan(Span rootSpan) {
if (this.rootSpan != null) {
throw new IllegalStateException("Root span already defined " + this.rootSpan);
logger.warn(
"Root span already defined "
+ this.rootSpan
+ ", can't overwrite root span with "
+ rootSpan);
}
this.rootSpan = rootSpan;
}
Expand All @@ -52,30 +56,34 @@ public Span getSpan(MavenProject mavenProject) {
MavenProjectKey key = MavenProjectKey.fromMavenProject(mavenProject);
Span span = this.mavenProjectKeySpanMap.get(key);
if (span == null) {
throw new IllegalStateException(
logger.warn(
"Span not started for project "
+ mavenProject.getGroupId()
+ ":"
+ mavenProject.getArtifactId());
return Span.getInvalid();
}
return span;
}

public Span getRootSpanNotNull() {
Span rootSpan = this.rootSpan;
if (rootSpan == null) {
throw new IllegalStateException("Root span not defined");
logger.warn("Root span not defined");
return Span.getInvalid();
}
return rootSpan;
}

public Span removeRootSpan() {
Span rootSpan = this.rootSpan;
if (rootSpan == null) {
throw new IllegalStateException("Root span not defined");
logger.warn("Root span not defined");
return Span.getInvalid();
}
if (!this.mojoExecutionKeySpanMap.isEmpty()) {
throw new IllegalStateException(

logger.warn(
"Remaining children spans: "
+ this.mojoExecutionKeySpanMap.keySet().stream()
.map(MojoExecutionKey::toString)
Expand All @@ -90,7 +98,7 @@ public void putSpan(Span span, MavenProject mavenProject) {
MavenProjectKey key = MavenProjectKey.fromMavenProject(mavenProject);
Span previousSpanForKey = mavenProjectKeySpanMap.put(key, span);
if (previousSpanForKey != null) {
throw new IllegalStateException("A span has already been started for " + mavenProject);
logger.warn("A span has already been started for " + mavenProject);
}
}

Expand All @@ -99,8 +107,7 @@ public void putSpan(Span span, MojoExecution mojoExecution, MavenProject project
MojoExecutionKey key = MojoExecutionKey.fromMojoExecution(mojoExecution, project);
Span previousSpanForKey = mojoExecutionKeySpanMap.put(key, span);
if (previousSpanForKey != null) {
throw new IllegalStateException(
"A span has already been started for " + mojoExecution + ", " + project);
logger.warn("A span has already been started for " + mojoExecution + ", " + project);
}
}

Expand All @@ -109,7 +116,8 @@ public Span removeSpan(MavenProject mavenProject) {
MavenProjectKey key = MavenProjectKey.fromMavenProject(mavenProject);
Span span = mavenProjectKeySpanMap.remove(key);
if (span == null) {
throw new IllegalStateException("No span found for " + mavenProject);
logger.warn("No span found for " + mavenProject);
return Span.getInvalid();
}
return span;
}
Expand All @@ -120,7 +128,8 @@ public Span removeSpan(MojoExecution mojoExecution, MavenProject project) {
MojoExecutionKey key = MojoExecutionKey.fromMojoExecution(mojoExecution, project);
Span span = mojoExecutionKeySpanMap.remove(key);
if (span == null) {
throw new IllegalStateException("No span found for " + mojoExecution + " " + project);
logger.warn("No span found for " + mojoExecution + " " + project);
return Span.getInvalid();
}
return span;
}
Expand Down