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

Improve error report when trying to create a reserved filename #4781

Closed
scabug opened this issue Jul 7, 2011 · 2 comments · Fixed by scala/scala#9959
Closed

Improve error report when trying to create a reserved filename #4781

scabug opened this issue Jul 7, 2011 · 2 comments · Fixed by scala/scala#9959

Comments

@scabug
Copy link

scabug commented Jul 7, 2011

When running scalac or scaladoc on an object or a class named "Con" (case insensitive),
the program will not be able to produce the corresponding output file (Con.class or Con.html),
but rather throw an error or crash:

X:>scalac ReservedFilename.scala
error: The system cannot find the file specified
one error found

X:>scaladoc ReservedFilename.scala
Exception in thread "main" java.io.FileNotFoundException: .\Con.html (The system cannot find the file specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:179)
at java.io.FileOutputStream.(FileOutputStream.java:70)
at scala.tools.nsc.doc.html.HtmlPage.writeFor(HtmlPage.scala:57)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$generate$1.apply(HtmlFactory.scala:101)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$generate$1.apply(HtmlFactory.scala:101)
at scala.tools.nsc.doc.html.HtmlFactory.writeTemplate$1(HtmlFactory.scala:113)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$writeTemplate$1$1.apply(HtmlFactory.scala:115)
at scala.tools.nsc.doc.html.HtmlFactory$$anonfun$writeTemplate$1$1.apply(HtmlFactory.scala:115)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
at scala.collection.immutable.List.map(List.scala:45)
at scala.tools.nsc.doc.html.HtmlFactory.writeTemplate$1(HtmlFactory.scala:115)
at scala.tools.nsc.doc.html.HtmlFactory.writeTemplates(HtmlFactory.scala:118)
at scala.tools.nsc.doc.html.HtmlFactory.generate(HtmlFactory.scala:101)
at scala.tools.nsc.doc.html.Doclet.generateImpl(Doclet.scala:10)
at scala.tools.nsc.doc.doclet.Generator.generate(Generator.scala:24)
at scala.tools.nsc.doc.DocFactory.generate$1(DocFactory.scala:117)
at scala.tools.nsc.doc.DocFactory.document(DocFactory.scala:120)
at scala.tools.nsc.ScalaDoc.process(ScalaDoc.scala:48)
at scala.tools.nsc.ScalaDoc$.main(ScalaDoc.scala:74)
at scala.tools.nsc.ScalaDoc.main(ScalaDoc.scala)

This is due to the "con" filename being a reserved one on Windows OS family (regardless of extension).

An improvement would be to detect when the filename "con" is about to be created and suggest an appropriate course of action instead of crashing. This could be anything ranging from a simple explanation (why the file cannot be created), a suggestion of renaming the object/class if possible or for instance, compiling on another OS and then packaging as a jar which would allow using the precompiled binaries on Windows.

@scabug
Copy link
Author

scabug commented Jul 7, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4781?orig=1
Reporter: @melezov
Affected Versions: 2.9.0
Attachments:

@scabug
Copy link
Author

scabug commented Jul 7, 2011

@melezov said:
There seem to be a lot of these reserved device names (con, prn, aux & nul being the most common):
(http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx)


Do not use the following reserved device names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.

At least it is a finite list that could be used for better error reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants