Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalArgumentException: Unknown ansi-escape [2m at index 262 inside string cannot be parsed into an fansi.Str #730

Closed
khajavi opened this issue Dec 11, 2022 · 8 comments · Fixed by #731

Comments

@khajavi
Copy link

khajavi commented Dec 11, 2022

Main.scala

object Main {
  def main(args: Array[String]): Unit = {
    val settings = mdoc
      .MainSettings()
      .withSiteVariables(Map("VERSION" -> "1.0.0"))
      .withArgs(args.toList)
      .withClasspath(
        {
          List(
            "/home/milad/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio_2.13/2.0.5/zio_2.13-2.0.5.jar",
            "/home/milad/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/izumi-reflect_2.13/2.2.2/izumi-reflect_2.13-2.2.2.jar",
            "/home/milad/.cache/coursier/v1/https/repo1.maven.org/maven2/dev/zio/zio-stacktracer_2.13/2.0.5/zio-stacktracer_2.13-2.0.5.jar"
          ).mkString(":")
        }
      )

    val exitCode = mdoc.Main.process(settings)
    if (exitCode != 0) sys.exit(exitCode)
  }
}

docs/index.md:

import zio._

trait Foo
trait Bar

object Main extends ZIOAppDefault {
 def run = (ZIO.service[Foo] *> ZIO.service[Bar]).provide(ZLayer.succeed(new Foo{}), ZLayer.succeed(new Bar{}))
}

build.sbt

ThisBuild / scalaVersion := "2.13.10"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.example"
ThisBuild / organizationName := "example"

lazy val root = (project in file("."))
  .settings(
    name := "zio-mdoc",
    libraryDependencies ++= Seq(
      "dev.zio" %% "zio" % "2.0.5",
      "dev.zio" %% "zio-test" % "2.0.5" % Test,
      "org.scalameta" %% "mdoc" % "2.3.6"
    ),
    testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
  )

Produced errors:

mdoc.internal.cli.FileException: /home/milad/sources/scala/zio-mdoc/docs/index.md
Caused by: java.lang.IllegalArgumentException: Unknown ansi-escape [2m at index 262 inside string cannot be parsed into an fansi.Str
	at fansi.ErrorMode$Throw$.handle(Fansi.scala:440)
	at fansi.ErrorMode$Throw$.handle(Fansi.scala:428)
	at fansi.Str$.apply(Fansi.scala:280)
	at fansi.Str$.implicitApply(Fansi.scala:227)
	at mdoc.internal.io.ConsoleReporter.error(ConsoleReporter.scala:52)
	at mdoc.internal.io.ConsoleReporter.error(ConsoleReporter.scala:48)
	at mdoc.internal.markdown.MarkdownCompiler.reportMessage(MarkdownCompiler.scala:225)
	at mdoc.internal.markdown.MarkdownCompiler.$anonfun$report$2(MarkdownCompiler.scala:212)
	at mdoc.internal.markdown.MarkdownCompiler.$anonfun$report$2$adapted(MarkdownCompiler.scala:185)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at mdoc.internal.markdown.MarkdownCompiler.report(MarkdownCompiler.scala:185)
	at mdoc.internal.markdown.MarkdownCompiler.compileSources(MarkdownCompiler.scala:114)
	at mdoc.internal.markdown.MarkdownCompiler.compile(MarkdownCompiler.scala:126)
	at mdoc.internal.markdown.MarkdownBuilder$.buildDocument(MarkdownBuilder.scala:32)
	at mdoc.internal.markdown.Processor.processScalaInputs(Processor.scala:189)
	at mdoc.internal.markdown.Processor.processScalaInputs(Processor.scala:156)
	at mdoc.internal.markdown.Processor.processDocument(Processor.scala:54)
	at mdoc.internal.markdown.Markdown$.toMarkdown(Markdown.scala:136)
	at mdoc.internal.cli.MainOps.handleMarkdown(MainOps.scala:94)
	at mdoc.internal.cli.MainOps.handleFile(MainOps.scala:122)
	at mdoc.internal.cli.MainOps.$anonfun$generateCompleteSite$1(MainOps.scala:168)
	at scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
	at scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
	at scala.collection.immutable.List.foldLeft(List.scala:79)
	at mdoc.internal.cli.MainOps.generateCompleteSite(MainOps.scala:167)
	at mdoc.internal.cli.MainOps.run(MainOps.scala:189)
	at mdoc.internal.cli.MainOps$.process(MainOps.scala:286)
	at mdoc.MainProcess.process(Main.scala:44)
	at mdoc.MainProcess.process$(Main.scala:43)
	at mdoc.Main$.process(Main.scala:13)
	at Main$.main(Main.scala:10)
	at Main.main(Main.scala)
info: Compiled in 1.49s (1 error)

Does anyone have any clues why mdoc cannot compile my markdown file?

@tgodzik
Copy link
Contributor

tgodzik commented Dec 12, 2022

Thanks for reporting looks like a bug within https://github.com/com-lihaoyi/PPrint though I can't see anything in your code that would cause it.

You can use the to-string modifier which will avoid using pprint. You should also see what is pprint choking on.

@khajavi
Copy link
Author

khajavi commented Dec 12, 2022

@tgodzik
Thank you for your reply
I changed the compile-only to to-string modifier and got the same errors.

@tgodzik
Copy link
Contributor

tgodzik commented Dec 12, 2022

Ach, that's right, it seems the issue is that the Console reported is trying to color the issue RED and it's failing to do so.

Would be great to figure out what is the error that is causing it and report it upstream to fansi. We should also make sure that we can revert to toString for Console reported if fansi has issues. Maybe even fansi is not needed there 🤔

@tgodzik
Copy link
Contributor

tgodzik commented Dec 12, 2022

What error do you get when compiling the snippet normally?

@khajavi
Copy link
Author

khajavi commented Dec 12, 2022

Colorful errors

image

@tgodzik
Copy link
Contributor

tgodzik commented Dec 12, 2022

Are you able to copy that in text form? We could try to isolate exactly what is breaking.

@khajavi
Copy link
Author

khajavi commented Dec 13, 2022

Yes I can:

/home/milad/sources/scala/zio-mdoc/src/main/scala/Main.scala:28:59


──── ZLAYER ERROR ────────────────────────────────────────────────────

 Ambiguous layers! I cannot decide which to use.
 You have provided more than one layer for the following type:

   Object is provided by:
      1. ZLayer.succeed({
        final class $anon extends Foo;
        new $anon()
      })
      2. ZLayer.succeed({
        final class $anon extends Bar;
        new $anon()
      })

──────────────────────────────────────────────────────────────────────


  def run = (ZIO.service[Foo] *> ZIO.service[Bar]).provide(ZLayer.succeed(new Foo{}), ZLayer.succeed(new Bar{}))

@tgodzik
Copy link
Contributor

tgodzik commented Dec 15, 2022

Looks like the issue is com-lihaoyi/fansi#46 we should be able to apply the same workaround

tgodzik added a commit to tgodzik/mdoc that referenced this issue Dec 15, 2022
Previously, some error messages might have been not able to be printed due to a bug in fansi com-lihaoyi/fansi#46

Now, we added a workaround that should help out here.

Fixes scalameta#730
tgodzik added a commit that referenced this issue Dec 18, 2022
Previously, some error messages might have been not able to be printed due to a bug in fansi com-lihaoyi/fansi#46

Now, we added a workaround that should help out here.

Fixes #730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants