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

Print methods of the Console effect should not depend on Abort[IOException] #1069

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

rcardin
Copy link
Contributor

@rcardin rcardin commented Feb 5, 2025

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:

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 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:

def checkErrors(using Frame): Boolean < IO

@@ -19,34 +19,41 @@ final case class Console(unsafe: Console.Unsafe):
* @param s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also update the top Console scaladoc with the rationale for not having a pending abort + the role of checkErrors? I think it's important to clearly flag this behavior to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let me know if the text works for you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect! thanks

@rcardin rcardin requested a review from fwbrasil February 5, 2025 20:28
@fwbrasil fwbrasil merged commit cdf9406 into getkyo:main Feb 5, 2025
3 checks passed
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 this pull request may close these issues.

Print methods of the Console effect should not depend on Abort[IOException]
2 participants