ianhinder/Kranc

Better Imported File Error Message

Closed this issue · 4 comments

When Kranc imports a merge file (for example with CreateKrankThornTT's MergeFiles option) and the import fails, the error message simply says that an import failed but doesn't give any indication for WHICH file couldn't be imported. It would be very helpful for debugging to output which file the import failed for.

Thanks for all your hard work!

Can you give more details of how you are using the MergeFiles option, and the exact error message that you get?

The way it works is that you give it the name of a directory, and it copies or merges all the files in that directory into the generated thorn. Theoretically, it shouldn't be possible for the Import to fail, because it is only importing files which should already exist. One possible issue is that all the imported files are all treated as text. In the case that a file is merged with a generated file, this only make sense for text files, since all the generated files are text files. In the case where the file is simply copied, it is still treated as text because the string @THORN_NAME@ is replaced in such files with the name of the thorn (before that feature was added, such files were simply copied, so binary files would have been allowed). Maybe the Mathematica Import function fails if it tries to import a non-text file as text. Obviously some more error checking is needed, and the way it works might need to be changed, but I need a bit more information to diagnose exactly what is going wrong in your case.

I am using MergeFiles to merge a whole directory tree with subdirectories. The problem was that my text editor (emacs) was, unbenknownst to me, making additional files in the merge directory as I worked in it. Some of these files were backups (with "~" postfixes or "#" prefixes) and some were symbolic links to nothing, which emacs uses as lock files (These have the ".#" prefix. See: http://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html). When it ran, Kranc tried to read in these files along with the rest of the directory and the import failed. It took a long time to hunt through the directory to find what was wrong.

Perhaps Mathematica tried to follow the broken symbolic link and raised a file-not-found error. The only error message I saw was an import fail and then a string manipulation failure where I was told that the commands
'StringReplace[$Failed,"@THORN_NAME@" -> the thorn name I was using]'
and
StringJoin[$Failed, a scheduled function name ]
failed.

In any case, other emacs users might want to be aware that this can be an issue and turn off lock files and automatic backup file generation.

I can't acccess the machine where the failure happened at the moment, but when I can, I will look up the precise full error message and include it.

Thanks - that makes sense. When you call Import[file] and file is a broken symbolic link, Mathematica generates a message which does not contain the filename, despite what the documentation for the Import::nffil message says. I have added code to report this as an error with the offending filename in the message (96830d5).

Kranc should have a set of filenames that it ignores when merging directories. This could include the emacs backup files and lock files, and probably version control files as well. This was already reported in #105. I have added this feature (d2cf2bd) and closed that ticket.

Thanks for your help!