Skip to content

Commit

Permalink
Improve error logging (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones authored Nov 11, 2024
1 parent b29d087 commit fd5fbff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
31 changes: 8 additions & 23 deletions bridge/src/main/java/com/github/sbt/avro/AvscFilesCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AvscFilesCompiler {

Expand Down Expand Up @@ -55,18 +56,10 @@ public void compileFiles(Set<AvroFileRef> files, File outputDirectory) {

if (!uncompiledFiles.isEmpty()) {
String failedFiles = uncompiledFiles.stream()
.map(AvroFileRef::toString)
.collect(Collectors.joining(", "));
SchemaGenerationException ex = new SchemaGenerationException(
String.format("Can not compile schema files: %s", failedFiles));
.flatMap(f -> Stream.ofNullable(compileExceptions.get(f)).map(e -> f.getFile().getName() + ": " + e.getMessage()))
.collect(Collectors.joining(",\n"));

for (AvroFileRef file : uncompiledFiles) {
Exception e = compileExceptions.get(file);
if (e != null) {
ex.addSuppressed(e);
}
}
throw ex;
throw new SchemaGenerationException("Can not compile schema files:\n" + failedFiles);
}
}

Expand All @@ -92,19 +85,11 @@ public void compileClasses(Set<Class<? extends SpecificRecord>> classes, File ou
}

if (!uncompiledClasses.isEmpty()) {
String failedFiles = uncompiledClasses.stream()
String failedClasses = uncompiledClasses.stream()
.map(Class::toString)
.collect(Collectors.joining(", "));
SchemaGenerationException ex = new SchemaGenerationException(
String.format("Can not re-compile class: %s", failedFiles));

for (Class<?> clazz : uncompiledClasses) {
Exception e = compileExceptions.get(clazz);
if (e != null) {
ex.addSuppressed(e);
}
}
throw ex;
.flatMap(c -> Stream.ofNullable(compileExceptions.get(c)).map(e -> c + ": " + e.getMessage()))
.collect(Collectors.joining(",\n"));
throw new SchemaGenerationException("Can not re-compile classes:\n" + failedClasses);
}
}

Expand Down
30 changes: 17 additions & 13 deletions plugin/src/main/scala/com/github/sbt/avro/SbtAvro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,30 @@ object SbtAvro extends AutoPlugin {
compiler.setCreateSetters(avroCreateSetters.value)
compiler.setOptionalGetters(avroOptionalGetters.value)

try {
val recs = records.map(avroClassLoader.loadClass)
val avdls = srcDirs.flatMap(d => (d ** AvroAvdlFilter).get())
val avscs = srcDirs.flatMap(d =>
(d ** AvroAvscFilter)
.get()
.map(avsc => new AvroFileRef(d, avsc.relativeTo(d).get.toString))
)
val avprs = srcDirs.flatMap(d => (d ** AvroAvrpFilter).get())

out.log.info(
s"Avro compiler ${avroVersion.value} using stringType=${avroStringType.value}"
)
val recs = records.map(avroClassLoader.loadClass)
val avdls = srcDirs.flatMap(d => (d ** AvroAvdlFilter).get())
val avscs = srcDirs.flatMap(d =>
(d ** AvroAvscFilter)
.get()
.map(avsc => new AvroFileRef(d, avsc.relativeTo(d).get.toString))
)
val avprs = srcDirs.flatMap(d => (d ** AvroAvrpFilter).get())

out.log.info(
s"Avro compiler ${avroVersion.value} using stringType=${avroStringType.value}"
)
try {
compiler.recompile(recs.toArray, outDir)
compiler.compileIdls(avdls.toArray, outDir)
compiler.compileAvscs(avscs.toArray, outDir)
compiler.compileAvprs(avprs.toArray, outDir)

(outDir ** SbtAvro.JavaFileFilter).get().toSet
} catch {
case e: Exception =>
out.log.err(e.getMessage)
// avoid stacktrace in sbt
throw new AlreadyHandledException(e)
} finally {
avroClassLoader.close()
}
Expand Down

0 comments on commit fd5fbff

Please sign in to comment.