Skip to content

Commit

Permalink
[KOGITO-8614] Improving log message
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Aug 1, 2023
1 parent a045817 commit 582f4b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

public abstract class ValidationDecorator {

protected final Map<String, Exception> exceptions;
protected final Map<String, Throwable> exceptions;

protected ValidationDecorator(Map<String, Exception> exceptions) {
protected ValidationDecorator(Map<String, Throwable> exceptions) {
this.exceptions = exceptions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class ValidationLogDecorator extends ValidationDecorator {

private static final Logger LOGGER = LoggerFactory.getLogger(ValidationLogDecorator.class);

public ValidationLogDecorator(Map<String, Exception> exceptions) {
public ValidationLogDecorator(Map<String, Throwable> exceptions) {
super(exceptions);
}

@Override
public void decorate() {
exceptions.forEach((processId, exception) -> LOGGER.error("Invalid process: '{}'", processId, exception));
exceptions.forEach((processId, exception) -> LOGGER.error("Invalid process: '{}'. Found error: {}", processId, exception));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class ProcessCodegen extends AbstractGenerator {

public static ProcessCodegen ofCollectedResources(KogitoBuildContext context, Collection<CollectedResource> resources) {
Map<String, byte[]> processSVGMap = new HashMap<>();
Map<String, Exception> processesErrors = new HashMap<>();
Map<String, Throwable> processesErrors = new HashMap<>();
boolean useSvgAddon = context.getAddonsConfig().useProcessSVG();
final List<GeneratedInfo<KogitoWorkflowProcess>> processes = resources.stream()
.map(CollectedResource::resource)
Expand All @@ -123,13 +123,13 @@ public static ProcessCodegen ofCollectedResources(KogitoBuildContext context, Co
GeneratedInfo<KogitoWorkflowProcess> generatedInfo = parseWorkflowFile(resource, WorkflowFormat.fromFileName(resource.getSourcePath()), context);
notifySourceFileCodegenBindListeners(context, resource, Collections.singletonList(generatedInfo.info()));
return Stream.of(addResource(generatedInfo, resource));
} else {
return Stream.empty();
}
} catch (ValidationException | ProcessParsingException e) {
} catch (ValidationException e) {
processesErrors.put(resource.getSourcePath(), e);
return Stream.empty();
} catch (ProcessParsingException e) {
processesErrors.put(resource.getSourcePath(), e.getCause());
}
return Stream.empty();
})
//Validate parsed processes
.map(processInfo -> validate(processInfo, processesErrors))
Expand All @@ -154,7 +154,7 @@ private static void notifySourceFileCodegenBindListeners(KogitoBuildContext cont
.ifPresent(notifier -> processes.forEach(p -> notifier.notify(new SourceFileCodegenBindEvent(p.getId(), resource.getSourcePath()))));
}

private static void handleValidation(KogitoBuildContext context, Map<String, Exception> processesErrors) {
private static void handleValidation(KogitoBuildContext context, Map<String, Throwable> processesErrors) {
if (!processesErrors.isEmpty()) {
ValidationLogDecorator decorator = new ValidationLogDecorator(processesErrors);
decorator.decorate();
Expand All @@ -165,7 +165,7 @@ private static void handleValidation(KogitoBuildContext context, Map<String, Exc
}
}

private static GeneratedInfo<KogitoWorkflowProcess> validate(GeneratedInfo<KogitoWorkflowProcess> processInfo, Map<String, Exception> processesErrors) {
private static GeneratedInfo<KogitoWorkflowProcess> validate(GeneratedInfo<KogitoWorkflowProcess> processInfo, Map<String, Throwable> processesErrors) {
Process process = processInfo.info();
try {
ProcessValidatorRegistry.getInstance().getValidator(process, process.getResource()).validate(process);
Expand Down Expand Up @@ -216,7 +216,7 @@ protected static GeneratedInfo<KogitoWorkflowProcess> parseWorkflowFile(Resource
try (Reader reader = r.getReader()) {
return ServerlessWorkflowParser.of(reader, format, context).getProcessInfo();
} catch (IOException | RuntimeException e) {
throw new ProcessParsingException("Could not parse file " + r.getSourcePath(), e);
throw new ProcessParsingException(e);
}
}

Expand All @@ -227,7 +227,7 @@ protected static Collection<Process> parseProcessFile(Resource r) {
Thread.currentThread().getContextClassLoader());
return xmlReader.read(reader);
} catch (SAXException | IOException e) {
throw new ProcessParsingException("Could not parse file " + r.getSourcePath(), e);
throw new ProcessParsingException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
package org.kie.kogito.codegen.process;

public class ProcessParsingException extends RuntimeException {
private static final long serialVersionUID = 1L;

public ProcessParsingException(Throwable cause) {
super(cause);
}

public ProcessParsingException(String s, Throwable e) {
super(s, e);
}
}

0 comments on commit 582f4b6

Please sign in to comment.