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

introduce KyoException #929

Merged
merged 3 commits into from
Dec 16, 2024
Merged

introduce KyoException #929

merged 3 commits into from
Dec 16, 2024

Conversation

fwbrasil
Copy link
Collaborator

No description provided.

class KyoException private[kyo] (
message: Text = null,
cause: Text | Throwable = null
)(using val frame: Frame) extends NoStackTrace:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
)(using val frame: Frame) extends NoStackTrace:
)(using val frame: Frame) extends Exception(message.toString, cause match { case cause: Throwable => cause; case _ => null }) with NoStackTrace:

Would it make sense to make this a subclass of Exception? The docs says about Exception (and it's subclasses)

indicates conditions that a reasonable application might want to catch

Is that the case here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can also avoid the NoStackTrace mixin (though perhaps it's useful for users to see) via an argument to Exception/Throwable's constructor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added extends Exception but kept the method overrides and NoStackTrace. We need to override getCause anyway to avoid synchronization (#331) and the logic to handle non-Throwable causes seems more opaque as constructor parameters.

We also need NoStackTrace to signal to the kernel that it shouldn't try to enrich the stack trace.

case cause: Text @unchecked => Maybe(cause)

val msg = frame.render(("⚠️ KyoException".red.bold :: Maybe(message).toList ::: detail.toList).map(_.show)*)
s"\n$msg\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the two \n really supposed to be there? Shouldn't formatting like this be potentially done by the users of getMessage instead of in getMessage itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's to provide better rendering in the console otherwise the top line gets in the same line as the exception type. I imagine we'll eventually need to provide more customization of this behavior since verbose logging during an error state can contribute to degradation but, for now, I think the better error reporting will be valuable to people trying out the library. Example output:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

provide better rendering in the console

Yeah, totally. But my point was that it seems like a concert of the code which does the rendering/printing/formatting of an exception to standard output. getMessage is generally implemented in a way which is independent/oblivious whether the target is standard output, HTML, JSON or whatever else.

It's a very small thing, so I don't mind at all, but it caught my attention, so I've mentioned it. Feel free to ignore 🙂

case _: Throwable => Absent
case cause: Text @unchecked => Maybe(cause)

val msg = frame.render(("⚠️ KyoException".red.bold :: Maybe(message).toList ::: detail.toList).map(_.show)*)
Copy link
Collaborator

Choose a reason for hiding this comment

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

it may be easier to use .getOrElse("").show to avoid the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The size of the list determines how many lines will be rendered

@fwbrasil fwbrasil merged commit bae2644 into main Dec 16, 2024
3 checks passed
@fwbrasil fwbrasil deleted the kyo-exception branch December 16, 2024 22:42
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.

3 participants