Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align exception from file-timestamp functions from different impl. #121

Merged
merged 1 commit into from Jan 23, 2018

Conversation

Projects
None yet
4 participants
@j-keck
Copy link
Contributor

commented Jan 20, 2018

  • The native implementations to get / set a file-timestamp throws
    a 'java.io.FileNotFoundException' where the Java based implementation
    throws a 'java.nio.file.NoSuchFileException' if the given file
    does not exists.

  • 'IO.getModifiedTimeOrZero' and 'IO.setModifiedTimeOrFalse' handles
    only 'java.io.FileNotFoundException'

  • Map 'NoSuchFileExeption' to 'FileNotFoundException' in the
    Java based implementation, so all implementations throws
    the same error.

fixes sbt/sbt/issues/3894

@eed3si9n eed3si9n added the ready label Jan 20, 2018

@dwijnand
Copy link
Member

left a comment

LGTM. Requesting review by @cunei for his thoughts.

@dwijnand dwijnand requested a review from cunei Jan 22, 2018

@dwijnand dwijnand changed the base branch from 1.x to 1.1.x Jan 22, 2018

@dwijnand dwijnand changed the base branch from 1.1.x to 1.x Jan 22, 2018

@dwijnand dwijnand changed the base branch from 1.x to 1.1.x Jan 22, 2018

@dwijnand dwijnand changed the base branch from 1.1.x to 1.x Jan 22, 2018

@dwijnand
Copy link
Member

left a comment

Sorry @j-keck, do you mind rebasing (or cherry-picking) this commit onto the 1.1.x branch? That way hopefully we can merge it for sbt 1.1.1.

@j-keck j-keck changed the base branch from 1.x to 1.1.x Jan 22, 2018

@j-keck

This comment has been minimized.

Copy link
Contributor Author

commented Jan 22, 2018

@dwijnand done, this pr is on top of 1.1.x

@dwijnand
Copy link
Member

left a comment

Thanks. Re-LGTM from me.

@cunei
Copy link
Contributor

left a comment

Thanks @j-keck, it looks good apart from a comment I left concerning stack traces.

try {
f
} catch {
case e: NoSuchFileException => throw new FileNotFoundException(e.getFile)

This comment has been minimized.

Copy link
@cunei

cunei Jan 22, 2018

Contributor

An issue here is that the original stack trace is lost. It is not a big problem since mapNoSuchFileException() is only used once, but if it were used from more than one method, it would not be clear which code path led to the exception. Normally that can be avoided by chaining exceptions; however, it just so happens that FileNotFoundException does not have a Throwable-based constructor, so chaining is a bit more difficult than usual. Still, there is a workaround:

case e: NoSuchFileException => throw new FileNotFoundException(e.getFile) {
  initCause(e)
  override def toString() = {
    val msg = getLocalizedMessage()
    getClass().getSuperclass().getName() + (if (msg == null) "" else (": " + msg))
  }
}

This will be reported as:

java.io.FileNotFoundException: filename
        at ...
Caused by: java.nio.file.NoSuchFileException: filename
        at ...

Where the second exception identifies the original stacktrace. The additional toString() is needed in order to keep the exception identifying itself as a FileNotFoundException in the printout.

This comment has been minimized.

Copy link
@dwijnand

dwijnand Jan 22, 2018

Member

I think you can just call initCause.

This comment has been minimized.

Copy link
@j-keck

j-keck Jan 22, 2018

Author Contributor

thanks for your suggestions.
yes, throw new FileNotFoundException(e.getFile).initCause(e) preserves the stacktrace - thanks:

[error] java.io.FileNotFoundException: /nothing
[error] 	at sbt.internal.io.JavaMilli$.mapNoSuchFileException(Milli.scala:334)
[error] 	at sbt.internal.io.JavaMilli$.getModifiedTime(Milli.scala:322)
[error] 	at sbt.internal.io.Milli$.getModifiedTime(Milli.scala:362)
[error] 	at sbt.io.IO$.getModifiedTime(IO.scala:1143)
...
[error] Caused by: java.nio.file.NoSuchFileException: /nothing
[error] 	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
[error] 	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
[error] 	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
...

should i make this change in a new commit, or amend the actual commit?

This comment has been minimized.

Copy link
@dwijnand

dwijnand Jan 22, 2018

Member

As you prefer.

align exception from file-timestamp functions from different impl.
 * The native implementations to get / set a file-timestamp throws
   a 'java.io.FileNotFoundException' where the Java based implementation
   throws a 'java.nio.file.NoSuchFileException' if the given file
   does not exists.

 * 'IO.getModifiedTimeOrZero' and 'IO.setModifiedTimeOrFalse' handles
   only 'java.io.FileNotFoundException'

 * Map 'NoSuchFileExeption' to 'FileNotFoundException' in the
   Java based implementation, so all implementations throws
   the same error.
@j-keck

This comment has been minimized.

Copy link
Contributor Author

commented Jan 23, 2018

done

@dwijnand dwijnand merged commit db7dbd0 into sbt:1.1.x Jan 23, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@dwijnand dwijnand removed the ready label Jan 23, 2018

@dwijnand

This comment has been minimized.

Copy link
Member

commented Jan 23, 2018

Thanks, @j-keck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.