Skip to content

Commit

Permalink
Safer parsing logic for system properties
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Jul 24, 2021
1 parent e25d7df commit 9bcea87
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@
package cats.effect
package unsafe

import scala.util.Try

private[unsafe] abstract class IORuntimeConfigCompanionPlatform { this: IORuntimeConfig.type =>

// TODO make the cancelation and auto-yield properties have saner names
protected final val Default: IORuntimeConfig = {
val cancelationCheckThreshold =
System.getProperty("cats.effect.cancelation.check.threshold", "512").toInt

apply(
cancelationCheckThreshold,
System
.getProperty("cats.effect.auto.yield.threshold.multiplier", "2")
.toInt * cancelationCheckThreshold,
System
.getProperty(
"cats.effect.tracing.exceptions.enhanced",
DefaultEnhancedExceptions.toString)
.toBoolean,
System
.getProperty("cats.effect.tracing.buffer.size", DefaultTraceBufferSize.toString)
.toInt
)
Try(System.getProperty("cats.effect.cancelation.check.threshold").toInt).getOrElse(512)

val autoYieldThreshold =
Try(System.getProperty("cats.effect.auto.yield.threshold.multiplier").toInt)
.getOrElse(2) * cancelationCheckThreshold

val enhancedExceptions =
Try(System.getProperty("cats.effect.tracing.exceptions.enhanced").toBoolean)
.getOrElse(DefaultEnhancedExceptions)

val traceBufferSize =
Try(System.getProperty("cats.effect.tracing.buffer.size").toInt)
.getOrElse(DefaultTraceBufferSize)

apply(cancelationCheckThreshold, autoYieldThreshold, enhancedExceptions, traceBufferSize)
}
}

0 comments on commit 9bcea87

Please sign in to comment.