Skip to content

Commit

Permalink
Improve stack traces formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 1, 2024
1 parent 632c442 commit 5680b83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Added
- Common Stack Trace frames skip in description and logs, by @HardNorth
### Changed
- Client version updated on [5.2.18](https://github.com/reportportal/client-java/releases/tag/5.2.18), by @HardNorth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.epam.reportportal.utils.AttributeParser;
import com.epam.reportportal.utils.ParameterUtils;
import com.epam.reportportal.utils.TestCaseIdUtils;
import com.epam.reportportal.utils.markdown.MarkdownUtils;
import com.epam.reportportal.utils.formatting.MarkdownUtils;
import com.epam.ta.reportportal.ws.model.*;
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
Expand Down Expand Up @@ -59,7 +59,7 @@
import static com.epam.reportportal.service.tree.TestItemTree.createTestItemLeaf;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace;
import static com.epam.reportportal.utils.formatting.ExceptionUtils.getStackTrace;

/*
* ReportPortal Extension sends the results of test execution to ReportPortal in RealTime
Expand Down Expand Up @@ -91,7 +91,7 @@ public class ReportPortalExtension
private final Map<ExtensionContext, Maybe<String>> idMapping = new ConcurrentHashMap<>();
private final Map<ExtensionContext, Maybe<String>> testTemplates = new ConcurrentHashMap<>();
private final Set<ExtensionContext> failedClassInits = Collections.newSetFromMap(new ConcurrentHashMap<>());
public static final String DESCRIPTION_TEST_ERROR_FORMAT = "%s\nError: \n%s";
public static final String DESCRIPTION_TEST_ERROR_FORMAT = "Error: \n%s";
@Nonnull
protected Optional<Maybe<String>> getItemId(@Nonnull ExtensionContext context) {
return ofNullable(idMapping.get(context));
Expand Down Expand Up @@ -764,9 +764,9 @@ protected FinishTestItemRQ buildFinishTestRq(@Nonnull ExtensionContext context,
ItemStatus myStatus = ofNullable(status).orElseGet(() -> getExecutionStatus(context));
Optional<Throwable> myException = context.getExecutionException();
if (status != ItemStatus.PASSED && myException.isPresent()) {
String description = String.format(DESCRIPTION_TEST_ERROR_FORMAT,
createStepDescription(context, STEP),
getStackTrace(myException.get()));
String stepDescription = createStepDescription(context, STEP);
String stackTrace = String.format(DESCRIPTION_TEST_ERROR_FORMAT, getStackTrace(myException.get(), new Throwable()));
String description = !stepDescription.trim().isEmpty() ? MarkdownUtils.asTwoParts(stepDescription, stackTrace) : stackTrace;
rq.setDescription(description);
}
ofNullable(status).ifPresent(s -> rq.setStatus(s.name()));
Expand Down Expand Up @@ -960,7 +960,7 @@ protected void sendStackTraceToRP(final Throwable cause) {
rq.setLevel("ERROR");
rq.setLogTime(Calendar.getInstance().getTime());
if (cause != null) {
rq.setMessage(getStackTrace(cause));
rq.setMessage(getStackTrace(cause, new Throwable()));
} else {
rq.setMessage("Test has failed without exception");
}
Expand Down

0 comments on commit 5680b83

Please sign in to comment.