2
0
Эх сурвалжийг харах

[lua] better error messages for missing/incorrect file input

Justin Donaldson 8 жил өмнө
parent
commit
6fceae2c85

+ 7 - 2
std/lua/_std/sys/io/File.hx

@@ -30,6 +30,7 @@ import lua.Boot;
 class File {
 	public static function getContent( path : String ) : String {
 		var f = Io.open(path, "r");
+		if (f == null) throw 'Invalid path : $path';
 		var s = f.read("*all");
 		f.close();
 		return s;
@@ -55,11 +56,15 @@ class File {
 	}
 
 	public static function read( path : String, binary : Bool = true ) : FileInput {
-		return new FileInput(Io.open(path, binary ? 'rb' : 'r'));
+		var fh = Io.open(path, binary ? 'rb' : 'r');
+		if (fh == null) throw 'Invalid path : $path';
+		return new FileInput(fh);
 	}
 
 	public static function write( path : String, binary : Bool = true ) : FileOutput {
-		return new FileOutput(Io.open(path, binary ? 'wb' : 'w'));
+		var fh = Io.open(path, binary ? 'wb' : 'w');
+		if (fh == null) throw 'Invalid path : $path';
+		return new FileOutput(fh);
 	}
 
 	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void {

+ 1 - 0
std/lua/_std/sys/io/FileInput.hx

@@ -35,6 +35,7 @@ class FileInput extends haxe.io.Input {
 	var _eof:Bool;
 
 	public function new(f:FileHandle){
+		if (f == null) throw 'Invalid filehandle : $f';
 		this.bigEndian = Boot.platformBigEndian;
 		this.f = f;
 		this._eof = false;

+ 1 - 0
std/lua/_std/sys/io/FileOutput.hx

@@ -27,6 +27,7 @@ class FileOutput extends haxe.io.Output {
 	var f:FileHandle;
 
 	public function new(f:FileHandle){
+		if (f == null) throw 'Invalid filehandle : $f';
 		this.f = f;
 	}