Skip to content

Commit 638ae3b

Browse files
authored
Improve error messages in require()-s (#397)
Useful for debugging, user friendlier than just: ``` [198] Exception in thread "Thread-2" java.lang.IllegalArgumentException: requirement failed [198] at scala.Predef$.require(Predef.scala:324) [198] at os.RelPath.asSubPath(Path.scala:345) [198] at os.SubPath$.apply(Path.scala:426) ```
1 parent bbe7948 commit 638ae3b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

os/src/Path.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class RelPath private[os] (segments0: Array[String], val ups: Int)
316316
def lastOpt = segments.lastOption
317317
val segments: IndexedSeq[String] = segments0.toIndexedSeq
318318
type ThisType = RelPath
319-
require(ups >= 0)
319+
require(ups >= 0, s"ups must be non-negative, but it is $ups in ${this.toString}")
320320
override protected[this] def make(p: Seq[String], ups: Int): RelPath = {
321321
new RelPath(p.toArray[String], ups + this.ups)
322322
}
@@ -342,7 +342,7 @@ class RelPath private[os] (segments0: Array[String], val ups: Int)
342342
def toNIO = java.nio.file.Paths.get(toString)
343343

344344
def asSubPath = {
345-
require(ups == 0)
345+
require(ups == 0, s"ups must be zero, but it is $ups in ${this.toString}")
346346
new SubPath(segments0)
347347
}
348348

@@ -388,7 +388,7 @@ class SubPath private[os] (val segments0: Array[String])
388388
val segments: IndexedSeq[String] = segments0.toIndexedSeq
389389
override type ThisType = SubPath
390390
override protected[this] def make(p: Seq[String], ups: Int): SubPath = {
391-
require(ups == 0)
391+
require(ups == 0, s"ups must be zero, but it is $ups in ${this.toString}")
392392
new SubPath(p.toArray[String])
393393
}
394394

0 commit comments

Comments
 (0)