Skip to content

Commit acf6ace

Browse files
committed
Handle cases for when a swoval PathWatchers.Event's RelPath has no last segment available
1 parent bd0d75a commit acf6ace

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,17 @@ object Build {
702702
case d: Directory =>
703703
// Filtering event for directories, to ignore those related to the .bloop directory in particular
704704
event =>
705-
val p = os.Path(event.getTypedPath.getPath.toAbsolutePath)
706-
val relPath = p.relativeTo(d.path)
707-
val isHidden = relPath.segments.exists(_.startsWith("."))
708-
def isScalaFile = relPath.last.endsWith(".sc") || relPath.last.endsWith(".scala")
709-
def isJavaFile = relPath.last.endsWith(".java")
705+
val p = os.Path(event.getTypedPath.getPath.toAbsolutePath)
706+
val relPath = p.relativeTo(d.path)
707+
val isHidden = relPath.segments.exists(_.startsWith("."))
708+
val pathLast = Try(relPath.last).toEither.orElse(Try(p.last).toEither) match {
709+
case Right(last) => last
710+
case Left(e) =>
711+
logger.log(WatchError(event, e))
712+
""
713+
}
714+
def isScalaFile = pathLast.endsWith(".sc") || pathLast.endsWith(".scala")
715+
def isJavaFile = pathLast.endsWith(".java")
710716
!isHidden && (isScalaFile || isJavaFile)
711717
case _ => _ => true
712718
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package scala.build.errors
2+
3+
import com.swoval.files.PathWatchers
4+
5+
class WatchError(event: PathWatchers.Event, cause: Throwable = null)
6+
extends BuildException(
7+
message = s"Error watching paths with the PathWatchers.Event: $event",
8+
positions = Nil,
9+
cause = cause
10+
)

0 commit comments

Comments
 (0)