@@ -2,10 +2,15 @@ const chalk = require('chalk');
2
2
const commander = require('commander');
3
3
const Table = require('cli-table3');
4
4
const { description } = require('../package.json');
5
+ const { globalConfig } = require("./config.js");
6
+ const os = require('os');
7
+ const Client = require("./client");
5
8
6
9
const cliConfig = {
7
- verbose: false,
8
- json: false
10
+ verbose: false,
11
+ json: false,
12
+ report: false,
13
+ reportData: {}
9
14
};
10
15
11
16
const parse = (data) => {
@@ -110,13 +115,49 @@ const drawJSON = (data) => {
110
115
}
111
116
112
117
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);
116
144
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
+ }
118
160
119
- process.exit(1)
120
161
}
121
162
122
163
const actionRunner = (fn) => {
0 commit comments