Skip to content

Commit

Permalink
improve errors handling during failed curl query, and test curl using…
Browse files Browse the repository at this point in the history
… github
  • Loading branch information
MathieuC authored and MathieuC committed May 8, 2021
1 parent 39b4585 commit ba94189
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
31 changes: 22 additions & 9 deletions packages/ExtensionStore/github_scrubber.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,19 +1286,29 @@ CURL.prototype.get = function (command, wait) {
}


CURL.prototype.runCommand = function (bin, command, wait){
CURL.prototype.runCommand = function (bin, command, wait, test){
if (typeof test === 'undefined') var test = false; // test will not print the output, just the errors

var p = new QProcess();
// The toonboom bundled curl doesn't seem to be equiped for ssh so we have to use unsafe mode
if (bin.indexOf("bin_3rdParty") != -1) command = ["-k"].concat(command)
if (bin.indexOf("bin_3rdParty") != -1) command = ["-k"].concat(command);
command = ["-s", "-S"].concat(command);

this.log.debug("starting process :" + bin + " " + command.join(" "));
p.start(bin, command);

p.waitForFinished(wait);

var readOut = p.readAllStandardOutput();
var readErr = p.readAllStandardError();
var errors = new QTextStream(readErr).readAll();
var output = new QTextStream(readOut).readAll();
this.log.debug("curl output: " + output);
if (!test) this.log.debug("curl output: " + output);
this.log.error("curl errors: " + errors.replace("\r", ""));

if (errors){
throw new Error(errors)
}

return output;
}
Expand All @@ -1315,6 +1325,7 @@ Object.defineProperty(CURL.prototype, "bin", {
var curl = [System.getenv("windir") + "/system32/curl.exe",
System.getenv("ProgramFiles") + "/Git/mingw64/bin/curl.exe",
specialFolders.bin + "/bin_3rdParty/curl.exe"];
var curl = [specialFolders.bin + "/bin_3rdParty/curl.exe"];
} else {
var curl = ["/usr/bin/curl",
"/usr/local/bin/curl",
Expand All @@ -1323,16 +1334,18 @@ Object.defineProperty(CURL.prototype, "bin", {

for (var i in curl) {
if ((new File(curl[i])).exists) {
this.log.log("CURL bin found, using: "+curl[i])
// testing connection
var bin = curl[i];
var test = this.runCommand(bin, ["ifconfig.me"], 500);
if (!test){
var error = "ExtensionStore: Couldn't establish a connexion.\nCheck that "+bin+" has internet access."
this.log.error(error)
}else{
try{
this.log.log("testing connexion by connecting to github.com")
this.runCommand(bin, ["https://www.github.com/"], 500, true);
this.log.log("CURL bin found, using: "+curl[i])
CURL.__proto__.bin = bin;
return bin;
}catch(err){
this.log.error(err);
var message = "ExtensionStore: Couldn't establish a connexion.\nCheck that "+bin+" has internet access.";
this.log.error(message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ExtensionStore/tbpackage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ExtensionStore",
"version": "0.1.3",
"version": "0.1.4",
"compatibility": "Harmony Premium 16",
"description": "Changelog: improved connexion error handling.",
"isPackage": "true",
Expand Down

0 comments on commit ba94189

Please sign in to comment.