Skip to content

Commit

Permalink
gracefully fail when getting repository for running haxelib as a libr…
Browse files Browse the repository at this point in the history
…ary (see #293)
  • Loading branch information
nadako committed Mar 12, 2016
1 parent 9e34d79 commit 55c1414
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
Binary file modified run.n
Binary file not shown.
57 changes: 32 additions & 25 deletions src/haxelib/client/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ class Main {
}

if (!isHaxelibRun && !settings.safe) {
var rep = getRepository();
var rep = null;
handleErrors(function() rep = getRepository());
if (FileSystem.exists(rep + HAXELIB_LIBNAME)) {
argcur = 0; // send all arguments
doRun(rep, HAXELIB_LIBNAME, null);
Expand Down Expand Up @@ -389,39 +390,45 @@ class Main {
Sys.println('Warning: Command `$cmd` is deprecated and will be removed in future. $message.');
default:
}
try {
handleErrors(function() {
if( c.net ) loadProxy();
c.f();
} catch( e : Dynamic ) {
if( e == "std@host_resolve" ) {
print("Host "+SERVER.host+" was not found");
print("Please ensure that your internet connection is on");
print("If you don't have an internet connection or if you are behing a proxy");
print("please download manually the file from http://lib.haxe.org/files/3.0/");
print("and run 'haxelib local <file>' to install the Library.");
print("You can also setup the proxy with 'haxelib proxy'.");
Sys.exit(1);
}
if( e == "Blocked" ) {
print("Http connection timeout. Try running haxelib -notimeout <command> to disable timeout");
Sys.exit(1);
}
if( e == "std@get_cwd" ) {
print("ERROR: Current working directory is unavailable");
Sys.exit(1);
}
if( settings.debug )
neko.Lib.rethrow(e);
print(Std.string(e));
Sys.exit(1);
}
});
return;
}
print("Unknown command "+cmd);
usage();
Sys.exit(1);
}

inline function handleErrors(fn:Void->Void) {
try {
fn();
} catch( e : Dynamic ) {
if( e == "std@host_resolve" ) {
print("Host "+SERVER.host+" was not found");
print("Please ensure that your internet connection is on");
print("If you don't have an internet connection or if you are behing a proxy");
print("please download manually the file from http://lib.haxe.org/files/3.0/");
print("and run 'haxelib local <file>' to install the Library.");
print("You can also setup the proxy with 'haxelib proxy'.");
Sys.exit(1);
}
if( e == "Blocked" ) {
print("Http connection timeout. Try running haxelib -notimeout <command> to disable timeout");
Sys.exit(1);
}
if( e == "std@get_cwd" ) {
print("ERROR: Current working directory is unavailable");
Sys.exit(1);
}
if( settings.debug )
neko.Lib.rethrow(e);
print(Std.string(e));
Sys.exit(1);
}
}

inline function createHttpRequest(url:String):Http {
var req = new Http(url);
if (haxe.remoting.HttpConnection.TIMEOUT == 0)
Expand Down

0 comments on commit 55c1414

Please sign in to comment.