-
Notifications
You must be signed in to change notification settings - Fork 57
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
Changes from 4 commits
099a51f
acf7e7b
44d0653
7ee73d9
6dce54d
53b642c
35a5400
dbe4b34
dfd1159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,14 @@ package kyo | |
|
||
import kyo.* | ||
import kyo.Ansi.* | ||
import kyo.internal.Environment | ||
import scala.util.control.NoStackTrace | ||
|
||
class KyoException private[kyo] ( | ||
message: Text | Null = null, | ||
cause: Text | Throwable | Null = null | ||
)(using val frame: Frame) extends Exception( | ||
Option(message) match | ||
case Some(message) => message.toString; | ||
case _ => null, | ||
class KyoException private[kyo] (message: Text = "", cause: Text | Throwable = "")(using val frame: Frame) | ||
extends Exception( | ||
message.toString, | ||
cause match | ||
case cause: Throwable => cause; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙀 is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's harmless :) |
||
case cause: Throwable => cause | ||
case _ => null | ||
) with NoStackTrace: | ||
|
||
|
@@ -27,8 +24,12 @@ class KyoException private[kyo] ( | |
case _: Throwable => Absent | ||
case cause: Text @unchecked => Maybe(cause) | ||
|
||
val msg = frame.render(("⚠️ KyoException".red.bold :: Maybe(message).toList ::: detail.toList).map(_.show)*) | ||
s"\n$msg\n" | ||
if Environment.isDevelopment then | ||
val msg = frame.render(("⚠️ KyoException".red.bold :: Maybe(message).toList ::: detail.toList).map(_.show)*) | ||
s"\n$msg\n" | ||
else | ||
detail.map(_.toString).getOrElse(null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
end if | ||
end getMessage | ||
|
||
end KyoException |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package kyo.internal | ||
|
||
/** Environment detection utility. | ||
* | ||
* Provides functionality to detect whether the JVM is running in a development environment. This information is used to control the | ||
* verbosity of error messages and debugging information in Kyo's implementations. | ||
* | ||
* The development mode can be controlled in two ways: | ||
* 1. Explicitly via the system property "-Dkyo.development-mode.enable=true" | ||
* 2. Automatically by detecting SBT in the classpath | ||
* }}} | ||
*/ | ||
private[kyo] object Environment: | ||
|
||
/** Determines if the execution is a development environment. | ||
* | ||
* This method checks the following conditions in order: | ||
* | ||
* 1. If system property "kyo.development-mode.enable" exists: | ||
* - Returns true if the property value is "true" (case insensitive) | ||
* - Returns false if the property value is anything else | ||
* 2. If the property doesn't exist: | ||
* - Returns true if SBT is detected in the classpath (contains "org.scala-sbt") | ||
* - Returns false otherwise | ||
* | ||
* @return | ||
* true if running in a development environment, false otherwise | ||
*/ | ||
val isDevelopment: Boolean = inferIsDevelopment() | ||
|
||
private[internal] def inferIsDevelopment(): Boolean = | ||
sys.props.get("kyo.development-mode.enable").map(_.toLowerCase) match | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. development can also be enabled explicitly via the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this. What would you think about
fwbrasil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case Some("true") => true | ||
case Some(_) => false | ||
case _ => sys.props.get("java.class.path").exists(_.contains("org.scala-sbt")) | ||
|
||
end Environment |
There was a problem hiding this comment.
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