Skip to content

Commit

Permalink
Issue 40:
Browse files Browse the repository at this point in the history
Make the error message in the browser more meaningful when the
file (i.e. div) cannot be openned.

There is no unit test because it is browser-only code.

During unit tests, open() calls turn into Sk.read() which handles missing
files properly already.
  • Loading branch information
csev committed Jan 24, 2013
1 parent fd83176 commit 5d984a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,13 @@ Sk.builtin.TimeLimitError = function(args) { Sk.builtin.Exception.apply(this, ar
goog.inherits(Sk.builtin.TimeLimitError, Sk.builtin.Exception);
Sk.builtin.TimeLimitError.prototype.tp$name = "TimeLimitError";
goog.exportSymbol("Sk.builtin.TimeLimitError", Sk.builtin.TimeLimitError);

/**
* @constructor
* @extends Sk.builtin.Exception
* @param {...*} args
*/
Sk.builtin.IOError = function(args) { Sk.builtin.Exception.apply(this, arguments); }
goog.inherits(Sk.builtin.IOError, Sk.builtin.Exception);
Sk.builtin.IOError.prototype.tp$name = "IOError";
goog.exportSymbol("Sk.builtin.IOError", Sk.builtin.IOError);
9 changes: 6 additions & 3 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ Sk.builtin.file = function(name, mode, buffering)
this.name = name;
this.closed = false;
if ( Sk.inBrowser ) { // todo: Maybe provide a replaceable function for non-import files
if (document.all) {
this.data$ = document.getElementById(name.v).innerText;
var elem = document.getElementById(name.v);
if ( elem == null) {
throw new Sk.builtin.IOError("[Errno 2] No such file or directory: '"+name.v+"'");
} else if (document.all) {
this.data$ = elem.innerText;
} else { // stupid Firefox
this.data$ = document.getElementById(name.v).textContent;
this.data$ = elem.textContent;
}
} else {
this.data$ = Sk.read(name.v);
Expand Down

0 comments on commit 5d984a6

Please sign in to comment.