GNOME Bugzilla – Bug 616423
Programm fails to start if it doesn't find the saved notebook directory
Last modified: 2010-08-28 20:24:02 UTC
Hi, I was asked to report this bug upstream and I thougth that's the right place, if not please let me know ... (I'm just copying the bug report from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572217#5) 1- Start reinteract and create a test notebook in a local directory: > ci@randog:~/prog/evo$ reinteract 2- Save the worksheet and the notebook and quit the programm > ci@randog:~/prog/test_r$ dir Test_notebook > ci@randog:~/prog/test_r$ cd Test_notebook/ > ci@randog:~/prog/test_r/Test_notebook$ dir index.rnb test\ ws.rws > ci@randog:~/prog/test_r/Test_notebook$ cat index.rnb [Notebook] last_modified = 1267534216.02 description = Test the notebook feature 3- Delete or move the directory where the notebook was saved > ci@randog:~/prog/test_r$ mv Test_notebook/ Test_notebook_moved > ci@randog:~/prog/test_r$ dir Test_notebook_moved 4- Try to start the programm and it will fail > ci@randog:~/prog/test_r$ reinteract Traceback (most recent call last):
+ Trace 221497
reinteract.main.main()
OSError: [Errno 2] No such file or directory: '/home/ci/prog/test_r/Test_notebook'
Thanks ! -- System Information: Debian Release: squeeze/sid APT prefers testing APT policy: (500, 'testing') Architecture: amd64 (x86_64) Kernel: Linux 2.6.32-trunk-amd64 (SMP w/2 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages reinteract depends on: ii python 2.5.4-9 An interactive high-level object-o ii python-gtk2 2.16.0-2 Python bindings for the GTK+ widge ii python-matplotlib 0.99.1.2-3 Python based plotting system in a ii python-support 1.0.6 automated rebuilding support for P Versions of packages reinteract recommends: pn sox <none> (no description available) reinteract suggests no packages. -- no debconf information
I can confirm this bug. It seems that while notebook_info is careful about checking for the existence of index.rnb, it doesn't check the existence of the directory before calling os.stat(). We could check for the directory before os.stat(), but it's not clear to me what to do if the directory doesn't exist. If it's gone, presumably it was deleted on purpose and the user would be surprised to have it keep popping back up. Maybe it's better to catch the Exception at the top of the stack and open the default notebook instead. I don't know if this would leave Reinteract in an inconsistent state, though.
Created attachment 159301 [details] [review] Patch This patch implements the second option I mention above in a brain-dead way. It just traps OSErrors bubbling up from within open_notebook(). If we really want to trap only the error of the directory not existing, it would probably be better to do that at the lower levels and raise a specific error. On the other hand, we could simply trap all error here, which might provide a partial solution to notebooks that cause Reinteract to crash when loaded. This code has been mixed up with checking that recent_notebooks is non-empty, in an effort to conserve code that is either clever or (more likely) confusing.
Created attachment 159389 [details] [review] Patch, ver. 2 A better way to handle errors in opening a notebook: Go through recent_notebooks until you find one that opens without error. If none does this, fallback on Main, creating it if necessary (as before). recent_notebooks being empty is handled naturally in this setup.
Review of attachment 159389 [details] [review]: Looks good, pushed. The one problem with catching OSError like this is that if some OSError is introduced anywhere inside the notebook loading code, it's really hard to debug, so there might be some argument for checking doing a double check of: if os.path.exist(dir): try: load(dir) except OSError, e: print >>sys.stderr, e But I think we can just let the person debugging the hypothetical OSError have a bad day :-)