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

pprint.apply fails for arbitrary Strings #35

Open
mattelacchiato opened this issue Dec 11, 2019 · 2 comments
Open

pprint.apply fails for arbitrary Strings #35

mattelacchiato opened this issue Dec 11, 2019 · 2 comments

Comments

@mattelacchiato
Copy link

We are using pprint in property based testing, where we create arbitrary strings. Sadly, pprint fails on some of those characters:
Message: Unknown ansi-escape at index 3 inside string cannot be parsed into an fansi.Str

Example:

import org.scalatest.WordSpec
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

class PprintUnitTest extends WordSpec with ScalaCheckPropertyChecks {
  "pprint" in {
    forAll(minSuccessful(5000000)) { s: String =>
      pprint.apply(s)
    }
  }
}
@lj-ditrapani
Copy link

Ran into this same issue. Using "com.lihaoyi" %% "pprint" % "0.7.1". Library chokes on certain strings. Had to remove use from production.

@TidyMaze
Copy link

TidyMaze commented Aug 23, 2023

same thing here, crash in production, we are still using the lib but with a safe wrapper

object PrettyPrintHelper extends LazyLogging {

  /**
   * Safe wrapper around pprint.
   * This method exists because of pprint not supporting some non-printable characters,
   * exploding with an exception when attempting to do so.
   *
   * See issue: https://github.com/com-lihaoyi/PPrint/issues/35
   */
  def safePrettyPrint(anyValue: Any): String = {
    Try(BlackWhite.apply(anyValue).toString()).fold(err => {
      logger.error(s"Failed to pretty print $anyValue with message: ${err.getMessage}", err)
      anyValue.toString
    }, identity)
  }

}

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

No branches or pull requests

3 participants