Skip to content

Commit 1251bff

Browse files
Merge pull request #852 from appwrite/feat-report-error
feat(cli): Adding report flag
2 parents ebc1464 + 3d2646a commit 1251bff

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

templates/cli/index.js.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ program
2929
.version(version, "-v, --version")
3030
.option("--verbose", "Show complete error log")
3131
.option("--json", "Output in JSON format")
32+
.option("--report", "Enable reporting in case of CLI errors")
3233
.on("option:json", () => {
3334
cliConfig.json = true;
3435
})
3536
.on("option:verbose", () => {
3637
cliConfig.verbose = true;
3738
})
39+
.on("option:report", function() {
40+
cliConfig.report = true;
41+
cliConfig.reportData = { data: this };
42+
})
3843
.showSuggestionAfterError()
3944
{% if sdk.test != "true" %}
4045
.addCommand(whoami)

templates/cli/lib/parser.js.twig

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ const chalk = require('chalk');
22
const commander = require('commander');
33
const Table = require('cli-table3');
44
const { description } = require('../package.json');
5+
const { globalConfig } = require("./config.js");
6+
const os = require('os');
7+
const Client = require("./client");
58

69
const cliConfig = {
7-
verbose: false,
8-
json: false
10+
verbose: false,
11+
json: false,
12+
report: false,
13+
reportData: {}
914
};
1015

1116
const parse = (data) => {
@@ -110,13 +115,49 @@ const drawJSON = (data) => {
110115
}
111116

112117
const parseError = (err) => {
113-
if(cliConfig.verbose) {
114-
console.error(err);
115-
}
118+
if (cliConfig.report) {
119+
(async () => {
120+
let appwriteVersion = 'unknown';
121+
const endpoint = globalConfig.getEndpoint();
122+
const isCloud = endpoint.includes('cloud.appwrite.io') ? 'Yes' : 'No';
123+
124+
try {
125+
const client = new Client().setEndpoint(endpoint);
126+
const res = await client.call('get', '/health/version');
127+
appwriteVersion = res.version;
128+
} catch {
129+
}
130+
131+
const version = '{{ sdk.version }}';
132+
const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args}\``;
133+
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud}`;
134+
135+
const stack = '```\n' + err.stack + '\n```';
136+
137+
const githubIssueUrl = new URL('https://github.com/appwrite/appwrite/issues/new');
138+
githubIssueUrl.searchParams.append('labels', 'bug');
139+
githubIssueUrl.searchParams.append('template', 'bug.yaml');
140+
githubIssueUrl.searchParams.append('title', `🐛 Bug Report: ${err.message}`);
141+
githubIssueUrl.searchParams.append('actual-behavior', `CLI Error:\n${stack}`);
142+
githubIssueUrl.searchParams.append('steps-to-reproduce', stepsToReproduce);
143+
githubIssueUrl.searchParams.append('environment', yourEnvironment);
116144

117-
error(err.message);
145+
log(`To report this error you can:\n - Create a support ticket in our Discord server https://appwrite.io/discord \n - Create an issue in our Github\n ${githubIssueUrl.href}\n`);
146+
147+
148+
error('\n Stack Trace: \n');
149+
console.error(err);
150+
process.exit(1);
151+
})()
152+
} else {
153+
if (cliConfig.verbose) {
154+
console.error(err);
155+
} else {
156+
error(err.message);
157+
}
158+
process.exit(1);
159+
}
118160

119-
process.exit(1)
120161
}
121162

122163
const actionRunner = (fn) => {

0 commit comments

Comments
 (0)