-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print methods of the Console effect should not depend on Abort[IOExce…
…ption] (#1069) Fixes #1037 ### Problem The Scala `Console.println` doesn't throw an `IOException`. The method uses the Java `PrintStream` type, which fails silently in case of errors. So, the `kyo.Console` effect should not depend upon an `Abort[IOException]` for printing text on the console. We should rewrite the code such that the examples in the documentation will change accordingly: ```scala val b: Unit < IO = Console.print("ok") // Print to stdout with a new line val c: Unit < IO = Console.printLine("ok") // Print to stderr val d: Unit < IO = Console.printErr("fail") // Print to stderr with a new line val e: Unit < IO = Console.printLineErr("fail") // Explicitly specifying the 'Console' implementation val f: Unit < IO = Console.let(Console.live)(e) ``` See [PrintWriter and PrintStream never throw IOExceptions](https://stackoverflow.com/questions/297303/printwriter-and-printstream-never-throw-ioexceptions) for further details. ### Solution I removed the `Abort[IOException]` effect from the return type of the `kyo.Console` methods concerning printing. Moreover, I added the following method, which returns whether the output or the error stream behind the `scala.Console` encountered an `IOException` error: ```scala 3 def checkErrors(using Frame): Boolean < IO ```
- Loading branch information
Showing
2 changed files
with
114 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters