Skip to content

Harden IDE: Catch NoSuchFileException #4002

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

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ object Interactive {
if (tree.pos.contains(pos)) {
// FIXME: We shouldn't need a cast. Change NavigateAST.pathTo to return a List of Tree?
val path = NavigateAST.pathTo(pos, tree, skipZeroExtent = true).asInstanceOf[List[untpd.Tree]]
path.dropWhile(!_.hasType).asInstanceOf[List[tpd.Tree]]
path.dropWhile(!_.hasType) collect { case t: tpd.Tree @unchecked => t }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If path can contain non-tree elements then hasType will also throws. Maybe change NavigateAST.pathTo to discard non-tree element and return a List[Tree] instead (as suggested in the comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Contributor Author

@odersky odersky Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the change on the other PR #3967

}
else Nil

Expand All @@ -365,7 +365,7 @@ object Interactive {
case nested :: encl :: rest =>
import typer.Typer._
val outer = contextOfPath(encl :: rest)
encl match {
try encl match {
case tree @ PackageDef(pkg, stats) =>
assert(tree.symbol.exists)
if (nested `eq` pkg) outer
Expand Down Expand Up @@ -401,6 +401,9 @@ object Interactive {
case _ =>
outer
}
catch {
case ex: CyclicReference => outer
}
}

/** The first tree in the path that is a definition. */
Expand Down
28 changes: 16 additions & 12 deletions compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,24 @@ class InteractiveDriver(settings: List[String]) extends Driver {
val names = new mutable.ListBuffer[String]
dirClassPaths.foreach { dirCp =>
val root = dirCp.dir.toPath
Files.walkFileTree(root, new SimpleFileVisitor[Path] {
override def visitFile(path: Path, attrs: BasicFileAttributes) = {
if (!attrs.isDirectory) {
val name = path.getFileName.toString
for {
tastySuffix <- tastySuffixes
if name.endsWith(tastySuffix)
} {
names += root.relativize(path).toString.replace("/", ".").stripSuffix(tastySuffix)
try
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (Files.exists(root)) ... instead of catching an exception?

Files.walkFileTree(root, new SimpleFileVisitor[Path] {
override def visitFile(path: Path, attrs: BasicFileAttributes) = {
if (!attrs.isDirectory) {
val name = path.getFileName.toString
for {
tastySuffix <- tastySuffixes
if name.endsWith(tastySuffix)
} {
names += root.relativize(path).toString.replace("/", ".").stripSuffix(tastySuffix)
}
}
FileVisitResult.CONTINUE
}
FileVisitResult.CONTINUE
}
})
})
catch {
case _: NoSuchFileException =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should emit an error or warning. If we don't add it in this PR we might have silent failures that are impossible to debug.

}
}
names.toList
}
Expand Down