Bug/Regression of Crash blocks in `2.2.23`
swoogles opened this issue · comments
This code was working on 2.2.22:
```scala mdoc
import zio.ZIO
import zio.Runtime.default.unsafeRun
def getTemperatureZ(behavior: String): ZIO[
Any,
GpsException | NetworkException,
String
] =
if (behavior == "GPS Error")
ZIO.fail(new GpsException())
else if (behavior == "Network Error")
// TODO Use a non-exceptional error
ZIO.fail(new NetworkException())
else
ZIO.succeed("30 degrees")
unsafeRun(getTemperatureZ("Succeed"))
```
... other prose and fences ...
```scala mdoc:crash
unsafeRun( getTemperatureZ("GPS Error") )
```
but now gives this error:
12_Hello_Failures.md:160 (mdoc generated code)
Line is indented too far to the left, or a `}` is missing
$doc.endStatement();
It's reporting the failure on a line before my mdoc:crash fence, regardless of what I put in between the 2 fences
I know the crash behavior just got updated with this last release, and I'm worried there was a regression of some kind. Instead of seeing an error with my src code, it's spitting out internal errors.
For the fullest context, this is the complete file: https://github.com/EffectOrientedProgramming/book/blob/main/Chapters/12_Hello_Failures.md
Thanks! We're definitely missing significant indentation examples in the CrashSuite.
The problem seems to be fairly simple, running on your repo just this file in verbose mode shows that the crash section wasn't rendered correctly:
$doc.crash(0, 0, 0, 14) {
import zio.ZIO
import zio.Runtime.default.unsafeRun
def getTemperatureZ(behavior: String): ZIO[
Any,
GpsException | NetworkException,
String
] =
if (behavior == "GPS Error")
ZIO.fail(new GpsException())
else if (behavior == "Network Error")
// TODO Use a non-exceptional error
ZIO.fail(new NetworkException())
else
ZIO.succeed("30 degrees")
unsafeRun(getTemperatureZ("Succeed"))
}
$doc.endStatement();
$doc.endSection();
$doc.startSection();
and Scala 3 is unhappy. In this case it's a problem interaction with the :nest
modifier - for Scala 3 we not only put each nested layer in separate objects, but we also need to align the indentation.
For future reference, here's the command I used to dump the generated code:
sbt:EffectOrientedProgramming> mdoc --in Chapters/12_Hello_Failures.md --verbose
I'll do a little more digging and will push a fix today/tomorrow hopefully
Heh, probably should've kept this open until actual release.
@swoogles mdoc publishes snapshots, so the fixed version is 2.2.23+1-452f1c4b-SNAPSHOT
Before I trigger a release, would you mind testing it on your repo? You will need resolvers += Resolver.sonatypeRepo("snapshots")
in both project/plugins.sbt
and build.sbt
to depend on the snapshot version.
I ran fixed mdoc on your repo and it was working, but I want to make sure it works for you too.
@keynmol Everything works smoothly again with this snapshot :)
Thanks!
I'll snatch up the next official release ASAP.