atrium icon indicating copy to clipboard operation
atrium copied to clipboard

wrong line number in stacktrace in case of inlined function

Open AliGolmirzaei opened this issue 4 years ago • 3 comments

Affected Version: 0.11.1 API (fluent-en_GB, cc or cc-infix): fluent-en_GB Platform (jvm, js, android): android Extension (none, kotlin 1.3): none (idk how to check this but iam using kotlin 1.3.70)

How to reproduce the problem

1- Get sample from https://github.com/robstoll/atrium/blob/master/samples/multiplatform/src/commonTest/kotlin/org/atriumlib/samples/mpp/SampleTest.kt 2- comment line 27 3- run the test

Describe the bug

In report the line number of error is incorrect. Report message is:

expected that subject: () -> kotlin.Unit        (org.atriumlib.samples.mpp.SampleTest$expectAnExceptionWithAMessageOccurred$1 <1472275943>)
◆ ▶ thrown exception when called: ❗❗ no exception occurred
    ◾ is instance of type: IllegalArgumentException (java.lang.IllegalArgumentException)
      » ▶ message: CANNOT evaluate representation as it is based on subject which is not defined.
            » is instance of type: String (kotlin.String) -- Class: java.lang.String
            » contains: 
              ⚬ value: "hello"        <2090113321>
                ⚬ ▶ number of matches: -1
                    ◾ is at least: 1

ch.tutteli.atrium.reporting.AtriumError
	at org.atriumlib.samples.mpp.SampleTest.expectAnExceptionWithAMessageOccurred(test.kt:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)

Expected behaviour

expect

at org.atriumlib.samples.mpp.SampleTest.expectAnExceptionWithAMessageOccurred(test.kt:45)

to point to a correct line number. probably 28


Note from @robstoll Please react with :+1: if you would like to see additional information in the stacktrace, the more upvotes the more likely I will implement it myself -- feel free to sponsor me, that would be a motivation too. You are of course welcome to work on this issue. Write I'll work on it as comment so that we can assign the task to you.

AliGolmirzaei avatar May 21 '20 13:05 AliGolmirzaei

Thanks for the report, I'll look into it later on. What I can say already is that Atrium is not generating the stack trace. We only create the AtriumError and the JVM is populating the stack trace. So I guess the error here is in Kotlin itself or rather in the way the SampleTest in common gets generated in JVM. I'll check and give you feedback.

robstoll avatar May 21 '20 14:05 robstoll

thank you

AliGolmirzaei avatar May 22 '20 11:05 AliGolmirzaei

It was like I thought, the problem is Kotlin if you want or rather inlining. The stacktrace points to the generate JVM class SampleTest where the line is actually correct:

   L11
    LINENUMBER 47 L11
    INVOKESTATIC ch/tutteli/atrium/domain/creating/Fun0AssertionsKt.getFun0Assertions ()Lch/tutteli/atrium/domain/creating/Fun0Assertions;
    ALOAD 1
    ALOAD 5
    INVOKEINTERFACE ch/tutteli/atrium/domain/creating/Fun0Assertions.isThrowing (Lch/tutteli/atrium/creating/Expect;Lkotlin/reflect/KClass;)Lch/tutteli/atrium/domain/creating/changers/ChangedSubjectPostStep; (itf)
   L12
    LINENUMBER 45 L12  <<<====
    ALOAD 2
    INVOKEVIRTUAL ch/tutteli/atrium/domain/creating/changers/ChangedSubjectPostStep.addToFeature (Lkotlin/jvm/functions/Function1;)Lch/tutteli/atrium/creating/Expect;

Intellij works around it (I guess by reading the generated meta file) and offers the possibility to jump to call side: stacktrace-intellij

I therefore removed the bug label and instead added enhancement and needs votes as it has no high prio for me as most user probably use intellij. What we could do:

  • read the meta-file as well (I hope Jetbrains made this part open, something to research) and then either:
  • manipulating the stacktrace, include the information of the meta-file or
  • add the info of the meta file as failure hint to the message

robstoll avatar May 25 '20 18:05 robstoll

closing this as there were no votes so far and the gain is not enough IMO as intellij supports the jump to the right place

robstoll avatar Aug 25 '22 20:08 robstoll