Skip to content

Commit

Permalink
Merge pull request #1849 from robstoll/bugfix/1803-workaround-js-doub…
Browse files Browse the repository at this point in the history
…le-print

improve workaround for js double ex msg printing, allow to query message
  • Loading branch information
robstoll authored Oct 27, 2024
2 parents 8aacea4 + 6647477 commit 4a1bf71
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,32 @@ actual class AtriumError private constructor(

internal actual constructor(message: String, rootAssertion: Assertion) : this(message, rootAssertion, Unit)



override val message: String?
get() {
// workaround for intellij's double print exception message problem. Intellij is outputting the message once
// as message and once as part of the stack-trace (no idea why they do it) -- see also
val process = js("process.env._") as? String
return if (process?.contains("idea") == true) {
"".also {
// if the process contains idea, then we assume we deal with intellij-idea and that it suffers
// from the double print exception message problem by outputting the message once as message and
// once as part of the stack-trace (no idea why they do it).
// Currently, kotlin calls `message` twice, once when populating the stacktrace and once when
// reporting the failure. To work around the bug we return an empty string for the `message`
// and instead print it when intellij most likely wants to report the failure
//
// we tried to sneak it into the stack (as it is a String) but it looks like intellij-idea does a
// post-processing of the stack and double prints it again *sight*
if (Error().stackBacktrace.first().contains("AtriumError")) {
println("\n" + internalMessage)
}
}
} else {
return process?.takeIf {
// if there is a process.env and it contains idea, then we assume we deal with intellij-idea
it.contains("idea")
}?.takeIf {
// Currently, kotlin calls `message` twice, once when populating the stacktrace (in this case the
// first stacktrace does not contain AtriumError) and once when reporting the failure (here AtriumError
// is in the first stacktrace). To work around the bug we return an empty string for the `message`
// and instead print it when intellij most likely wants to report the failure
// (with the benefit that we get coloured code).
//
// we tried to sneak the message into the stack (as it is a String) instead of printing it but it looks
// like intellij-idea does a post-processing of the stack and double prints it again *sight*
// in any case, the added benefit of a coloured output seems worth this hack.
val stack = Error().stackBacktrace
stack.first().startsWith("AtriumError") && stack.any { it.startsWith("Runner.fail") }
}?.let {
println("\n" + internalMessage)
""
} ?: run {
internalMessage
}
}
Expand Down

0 comments on commit 4a1bf71

Please sign in to comment.