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

[data] introduce Environment and improve KyoException #1057

Merged
merged 9 commits into from
Jan 28, 2025

Conversation

fwbrasil
Copy link
Collaborator

@fwbrasil fwbrasil commented Jan 28, 2025

Problem

KyoException is too verbose in production environments. It's designed to improve the development experience by showing errors with the Frame information but, in a production environment, the overhead to log failures can significantly contribute to performance degradation.

Solution

Introduce Environment that enables the verbose mode only if the user explicitly enables the development mode or sbt entries are present in the classpath, which should be the case for Kyo development environments since we recommend both sbt and metals. The risk of false positives seems low since the check is strict.

Notes

I've also improved KyoException because I noticed a NullPointerException.

Option(message) match
case Some(message) => message.toString;
case _ => null,
class KyoException private[kyo] (message: Text = "", cause: Text | Throwable = "")(using val frame: Frame)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fall back to empty string instead of null

object Environment:

def isDevelopment(): Boolean =
sys.props.get("kyo.development-mode.enable").map(_.toLowerCase) match
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

development can also be enabled explicitly via the kyo.development-mode.enable system property

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding this. What would you think about kyo.development?

cause match
case cause: Throwable => cause;
Copy link
Contributor

Choose a reason for hiding this comment

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

🙀 is the ; the cause of the trouble? I'm so sorry 😿

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's harmless :)

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

Choose a reason for hiding this comment

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

How about .fold("")(_.take(1000).toString)?

@fwbrasil fwbrasil merged commit ad93322 into main Jan 28, 2025
2 of 3 checks passed
@fwbrasil fwbrasil deleted the environment-kyoexception branch January 28, 2025 21:09
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