com-lihaoyi/os-lib

`os/package.scala` can throw a Fatal exception

virusdave opened this issue · 1 comments

Specifically

val pwd: Path = os.Path(new java.io.File("").getCanonicalPath)

This can fail by:

: java.lang.ExceptionInInitializerError: null
:         at os.proc$$anonfun$spawn$4.apply(ProcessOps.scala:219) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
:         at scala.Option.getOrElse(Option.scala:121) ~[3rdparty.jvm.enumeratum-2.jar:?]
:         at os.proc.spawn(ProcessOps.scala:219) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
:         at os.proc.stream(ProcessOps.scala:101) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
:         at os.proc.call(ProcessOps.scala:61) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
: Caused by: java.lang.IllegalArgumentException: requirement failed: ? is not an absolute path
:         at scala.Predef$.require(Predef.scala:224) ~[3rdparty.jvm.enumeratum-2.jar:?]
:         at os.Path.<init>(Path.scala:327) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
:         at os.Path$.apply(Path.scala:287) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
:         at os.package$.<init>(package.scala:19) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]
:         at os.package$.<clinit>(package.scala) ~[3rdparty.jvm.lihaoyi-os-lib-0.jar:?]

Context: I was trying to us os.proc.call(), wrapped in a Try { } block in case it failed. Much to my surprise, this process died in prod with an exception that is excluded from NonFatal(), due apparently to os.File's constructor not liking the return value from new java.io.File("").getCanonicalPath apparently.

I see you addressed a similar issue here:
com-lihaoyi/Ammonite#376

Ultimately, i expect that Path's constructor should not be throwing like this, so should probably be less sensitive to the underlying FS implementation perhaps?

This is with version 0.2.9 for scala 2.11

Swapped over to using java.nio to do this in master, hopefully that should be a bit more robust