Skip to content

os/package.scala can throw a Fatal exception #24

@virusdave

Description

@virusdave

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions