Skip to content

Commit

Permalink
fix(cli): CLI error handling & changes error message (#1823)
Browse files Browse the repository at this point in the history
* fix(cli) : file not found error resolved

* fix(cli) : error message issues resolved

* feat(cli) : package.json updated
  • Loading branch information
soumyadip007 committed Jul 28, 2022
1 parent 0057c0f commit cdf14b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@spaship/cli",
"description": "A command line interface for SPAship!",
"version": "1.5.2",
"version": "1.5.3",
"author": "mclayton@redhat.com",
"bin": {
"spaship": "./bin/run"
Expand Down
17 changes: 8 additions & 9 deletions packages/cli/src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class DeployCommand extends Command {
data.append("name", name);
data.append("path", path);
data.append("ref", this.getRef(flags));
if (!fs.existsSync(args.archive)) {
spinner.fail(`${args.archive} not found in the directory, Please provide a valid file.`);
return;
}
data.append("upload", fs.createReadStream(args.archive));

const response = await DeployService.upload(host, data, apikey, (progress) => {
Expand All @@ -149,15 +153,10 @@ class DeployCommand extends Command {
this.log(`Total: ${Math.round((endTime - startTime) / 1000)} seconds`);
this.log(response);
} catch (e) {
if (step === "processing") {
spinner.info("Lost connection with SPAship server during processing.");
this.log(
`Lost connections usually still result in successful deployments, and are caused by a simple network timeout during archive processing. Please confirm your deployment succeeded by checking the SPAship UI, and checking your application in the environment you deployed to. To avoid timeouts, reduce the size of your application to help speed up processing.`
);
} else {
spinner.fail(e.message);
this.error(e, { exit: 1 });
}
spinner.fail(e.message);
e.includes("ENOTFOUND")
? this.error(`${host} is not valid, please check the Deployment URL`, { exit: 1 })
: this.error(e, { exit: 1 });
}
}

Expand Down
16 changes: 7 additions & 9 deletions packages/cli/src/services/deployService.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,31 @@ const upload = (url, data, apiKey, onUploadProgress) => {
} else if (res.statusCode >= 400 && res.statusCode < 500) {
switch (res.statusCode) {
case 400:
reject("Error: Failed to deploy. [400]");
reject("Failed to deploy, Please check the Deployment URL or File type. [400]");
break;
case 401:
reject(`Error: The API key was not accepted by ${url} [401]`);
reject(`The API key was not accepted by ${url} [401]`);
default:
reject(`Error: Failed to deploy with an unknown error. [${res.statusCode}]`);
reject(`Failed to deploy with an unknown error. [${res.statusCode}]`);
}
} else if (res.statusCode >= 500 && res.statusCode < 600) {
switch (res.statusCode) {
case 500:
reject(
`Error: The SPAship server has encountered a mysterious problem; someone call Richard Feynman! [500]`
);
reject(`The SPAship server has encountered a mysterious problem; someone call Richard Feynman! [500]`);
break;
case 501:
reject(
`Error: The spaship CLI attempted an action not supported by the server, possible version mismatch. [501]`
`The spaship CLI attempted an action not supported by the server, possible version mismatch. [501]`
);
break;
default:
reject(`Error: Unknown. [${res.statusCode}]`);
reject(`Unknown. [${res.statusCode}]`);
}
} else {
}
} catch (e) {
reject(
"Error: the server returned an invalid message. The server may be down, or your .spashiprc.yml may be pointing at the wrong server."
"The server returned an invalid message. The server may be down, or your .spashiprc.yml may be pointing at the wrong server (Please upgrade your CLI version and try again)."
);
}
});
Expand Down

0 comments on commit cdf14b0

Please sign in to comment.