Skip to content

recoverStackTrace breaks exception message #1631

@orange-buffalo

Description

@orange-buffalo

Consider the following test case:

class ExceptionTest {
    @Test
    fun `should preserve exception message`() {
        Assertions.assertThatThrownBy {
            runBlocking {
                withContext(newFixedThreadPoolContext(10, "my-context")) {
                    throw MyTokenException("42")
                }
            }
        }.isInstanceOf(MyTokenException::class.java).hasMessage("Token 42 is not valid")
    }
}

class MyTokenException(token: String) : RuntimeException("Token $token is not valid")

It is failing on message assertion:

Expecting message to be:
  <"Token 42 is not valid">
but was:
  <"Token Token 42 is not valid is not valid">

It looks like recoverStackTrace / tryCopyException incorrectly recovers the exception. #1040 mentions that similar problem is fixed in 1.2.0, but this test fails on 1.3.2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions