Skip to content

Commit ca586d3

Browse files
author
Arvid Paeglit
committed
Merge branch 'master' into dashboard_dc_ignore
# Conflicts: # src/deepcode/DeepCodeExtension.ts # src/deepcode/utils/vscodeCommandsUtils.ts
2 parents 2ac2fc8 + 0ae8a88 commit ca586d3

9 files changed

Lines changed: 172 additions & 82 deletions

File tree

src/deepcode/DeepCodeExtension.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DEEPCODE_OPEN_LOCAL,
1515
} from "./constants/commands";
1616
import { openDeepcodeSettingsCommand, createDCIgnoreCommand } from "./utils/vscodeCommandsUtils";
17+
import { errorsLogs } from "./messages/errorsServerLogMessages";
1718

1819
import {
1920
DEEPCODE_VIEW_SUPPORT,
@@ -23,24 +24,42 @@ import { SupportProvider } from "./view/SupportProvider";
2324
import { IssueProvider } from "./view/IssueProvider";
2425

2526
class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterface {
27+
private async executeCommand(
28+
name: string,
29+
fn: (...args: any[]) => Promise<any>,
30+
...args: any[]
31+
): Promise<any> {
32+
try {
33+
await fn(...args);
34+
} catch (error) {
35+
this.processError(error, {
36+
message: errorsLogs.command(name),
37+
});
38+
}
39+
}
40+
2641
public activate(context: vscode.ExtensionContext): void {
2742
this.statusBarItem.show();
2843

2944
context.subscriptions.push(
3045
vscode.commands.registerCommand(
3146
DEEPCODE_OPEN_BROWSER,
32-
(url: string) => open(url)
47+
this.executeCommand.bind(
48+
this,
49+
DEEPCODE_OPEN_BROWSER,
50+
(url: string) => open(url)
51+
)
3352
)
3453
);
3554

3655
context.subscriptions.push(
3756
vscode.commands.registerCommand(
3857
DEEPCODE_OPEN_LOCAL,
3958
(path: vscode.Uri, range?: vscode.Range) => {
40-
console.log("DEEPCODE_OPEN_LOCAL",path.toString());
4159
vscode.window.showTextDocument(path, { selection: range }).then(
42-
(f) => console.log(f),
43-
(err) => console.error(err)
60+
() => {}, (err) => this.processError(err, {
61+
message: errorsLogs.command(DEEPCODE_OPEN_LOCAL),
62+
})
4463
);
4564
}
4665
)
@@ -49,28 +68,44 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
4968
context.subscriptions.push(
5069
vscode.commands.registerCommand(
5170
DEEPCODE_LOGIN,
52-
this.initiateLogin.bind(this)
71+
this.executeCommand.bind(
72+
this,
73+
DEEPCODE_LOGIN,
74+
this.initiateLogin.bind(this)
75+
)
5376
)
5477
);
5578

5679
context.subscriptions.push(
5780
vscode.commands.registerCommand(
5881
DEEPCODE_APPROVE,
59-
this.approveUpload.bind(this)
82+
this.executeCommand.bind(
83+
this,
84+
DEEPCODE_APPROVE,
85+
this.approveUpload.bind(this)
86+
)
6087
)
6188
);
6289

6390
context.subscriptions.push(
6491
vscode.commands.registerCommand(
6592
DEEPCODE_START_COMMAND,
66-
this.startExtension.bind(this)
93+
this.executeCommand.bind(
94+
this,
95+
DEEPCODE_START_COMMAND,
96+
this.startExtension.bind(this)
97+
)
6798
)
6899
);
69100

70101
context.subscriptions.push(
71102
vscode.commands.registerCommand(
72103
DEEPCODE_SETTINGS_COMMAND,
73-
openDeepcodeSettingsCommand
104+
this.executeCommand.bind(
105+
this,
106+
DEEPCODE_SETTINGS_COMMAND,
107+
openDeepcodeSettingsCommand
108+
)
74109
)
75110
);
76111

@@ -92,7 +127,9 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
92127
);
93128

94129
this.activateAll();
95-
this.startExtension();
130+
this.startExtension().catch((err) => this.processError(err, {
131+
message: errorsLogs.failedExecution,
132+
}));
96133
}
97134

98135
}

src/deepcode/lib/modules/BaseDeepCodeModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ export default abstract class BaseDeepCodeModule implements DeepCode.BaseDeepCod
7474
}
7575

7676
get uploadApproved(): boolean {
77-
return this.staticUploadApproved || this.source !== IDE_NAME || !!(vscode.workspace.getConfiguration('deepcode').get('uploadApproved'));
77+
return this.staticUploadApproved || this.source !== IDE_NAME || !!(vscode.workspace.getConfiguration('deepcode').get<boolean>('uploadApproved'));
7878
}
7979

8080
async setUploadApproved(value = true): Promise<void> {
8181
await vscode.workspace.getConfiguration('deepcode').update('uploadApproved', value, true);
8282
}
8383

8484
get shouldReportErrors(): boolean {
85-
return !!vscode.workspace.getConfiguration('deepcode').get('yesCrashReport');
85+
return !!vscode.workspace.getConfiguration('deepcode').get<boolean>('yesCrashReport');
8686
}
8787

8888
get shouldReportEvents(): boolean {
89-
return !!vscode.workspace.getConfiguration('deepcode').get('yesTelemetry');
89+
return !!vscode.workspace.getConfiguration('deepcode').get<boolean>('yesTelemetry');
9090
}
9191

9292
// Avoid refreshing context/views too often:

src/deepcode/lib/modules/BundlesModule.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ abstract class BundlesModule extends LoginModule
102102

103103
onError(error: Error) {
104104
this.terminateAnalysis();
105-
this.processError(error);
105+
this.processError(error, {
106+
message: errorsLogs.failedServiceAI,
107+
});
106108
}
107109

108110
// processing workspaces
@@ -132,7 +134,13 @@ abstract class BundlesModule extends LoginModule
132134

133135
// procesing filter list of files, acceptable for server
134136
public async createFilesFilterList(): Promise<void> {
135-
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
137+
try {
138+
this.serverFilesFilterList = await http.getFilters(this.baseURL, this.token);
139+
} catch (err) {
140+
this.processError(err, {
141+
message: errorsLogs.filtersFiles
142+
})
143+
}
136144
}
137145

138146
private terminateAnalysis(): void {
@@ -193,7 +201,11 @@ abstract class BundlesModule extends LoginModule
193201
this.onError(error);
194202
});
195203

196-
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch((error) => this.onError(error));
204+
http.analyse(this.baseURL, this.token, path, this.files, removedFiles).catch(
205+
(error) => this.processError(error, {
206+
message: errorsLogs.analyse
207+
})
208+
);
197209
}
198210

199211
private async startCollectingFiles(
@@ -274,25 +286,27 @@ abstract class BundlesModule extends LoginModule
274286
try {
275287
const workspaceFolders: readonly vscode.WorkspaceFolder[] | undefined = vscode.workspace.workspaceFolders;
276288
if (!workspaceFolders || !workspaceFolders.length) {
277-
setContext(DEEPCODE_CONTEXT.ANALYZING, false);
289+
await setContext(DEEPCODE_CONTEXT.ANALYZING, false);
278290
return;
279291
}
280292

281293
this.createWorkspacesList(workspaceFolders);
282294

283295
if (this.workspacesPaths.length) {
284-
setContext(DEEPCODE_CONTEXT.ANALYZING, true);
296+
await setContext(DEEPCODE_CONTEXT.ANALYZING, true);
285297
this.updateCurrentWorkspacePath(this.workspacesPaths[0]);
286298

287299
await this.updateHashesBundles();
288300
for await (const path of this.workspacesPaths) {
289301
await this.performBundlesActions(path);
290302
}
291303
} else {
292-
setContext(DEEPCODE_CONTEXT.ANALYZING, false);
304+
await setContext(DEEPCODE_CONTEXT.ANALYZING, false);
293305
}
294306
} catch(err) {
295-
await this.processError(err);
307+
await this.processError(err, {
308+
message: errorsLogs.failedAnalysis,
309+
});
296310
}
297311
}
298312
}

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import BundlesModule from "./BundlesModule";
44
import { setContext } from "../../utils/vscodeCommandsUtils";
55
import { DEEPCODE_CONTEXT } from "../../constants/views";
66
import { EXECUTION_DEBOUNCE_INTERVAL } from "../../constants/general";
7+
import { errorsLogs } from "../../messages/errorsServerLogMessages";
78

89
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
9-
private executing = false;
10-
1110
activateAll(): void {
1211
// this.filesWatcher.activate(this);
1312
this.workspacesWatcher.activate(this);
@@ -18,7 +17,7 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
1817

1918
private async executeExtensionPipeline(): Promise<void> {
2019
console.log("DeepCode: starting execution pipeline");
21-
setContext(DEEPCODE_CONTEXT.ERROR, false);
20+
await setContext(DEEPCODE_CONTEXT.ERROR, false);
2221

2322
const loggedIn = await this.checkSession();
2423
if (!loggedIn) return;
@@ -36,7 +35,9 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
3635
try {
3736
await this.executeExtensionPipeline();
3837
} catch (err) {
39-
this.processError(err);
38+
this.processError(err, {
39+
message: errorsLogs.failedExecutionDebounce,
40+
});
4041
}
4142
},
4243
EXECUTION_DEBOUNCE_INTERVAL,

src/deepcode/lib/modules/LoginModule.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
1717

1818
this.pendingLogin = true;
1919
try {
20-
setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
20+
await setContext(DEEPCODE_CONTEXT.LOGGEDIN, false);
2121
const result = await http.login(this.baseURL, this.source);
2222
const { sessionToken, loginURL } = result;
2323
if (!sessionToken || !loginURL) {
@@ -27,7 +27,9 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
2727
await viewInBrowser(loginURL);
2828
await this.waitLoginConfirmation();
2929
} catch (err) {
30-
await this.processError(err, { message: errorsLogs.login });
30+
await this.processError(err, {
31+
message: errorsLogs.login
32+
});
3133
} finally {
3234
this.pendingLogin = false;
3335
}
@@ -36,9 +38,15 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
3638
async checkSession(): Promise<boolean> {
3739
let validSession = false;
3840
if (this.token) {
39-
validSession = !!(await http.checkSession(this.baseURL, this.token));
41+
try {
42+
validSession = !!(await http.checkSession(this.baseURL, this.token));
43+
} catch (err) {
44+
this.processError(err, {
45+
message: errorsLogs.loginStatus
46+
});
47+
}
4048
}
41-
setContext(DEEPCODE_CONTEXT.LOGGEDIN, validSession);
49+
await setContext(DEEPCODE_CONTEXT.LOGGEDIN, validSession);
4250
return validSession;
4351
}
4452

@@ -57,13 +65,13 @@ abstract class LoginModule extends ReportModule implements DeepCode.LoginModuleI
5765

5866
async checkApproval(): Promise<boolean> {
5967
const approved = this.uploadApproved;
60-
setContext(DEEPCODE_CONTEXT.APPROVED, approved);
68+
await setContext(DEEPCODE_CONTEXT.APPROVED, approved);
6169
return approved;
6270
}
6371

6472
async approveUpload(): Promise<void> {
65-
this.setUploadApproved(true);
66-
this.checkApproval();
73+
await this.setUploadApproved(true);
74+
await this.checkApproval();
6775
}
6876

6977
}

src/deepcode/lib/modules/ReportModule.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,37 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
2424

2525
async sendError(options: {[key: string]: any}): Promise<void> {
2626
if (!this.shouldReport || !this.shouldReportErrors) return;
27-
await http.sendError(this.baseURL, {
28-
source: this.source,
29-
...(this.token && { sessionToken: this.token }),
30-
...options
31-
});
27+
try {
28+
await http.sendError(this.baseURL, {
29+
source: this.source,
30+
...(this.token && { sessionToken: this.token }),
31+
...options
32+
});
33+
} catch(error) {
34+
console.error(error);
35+
}
3236
}
3337

3438
async sendEvent(event: string, options: {[key: string]: any}): Promise<void> {
3539
if (!this.shouldReport || !this.shouldReportEvents) return;
36-
await http.sendEvent(this.baseURL, {
37-
type: event,
38-
source: this.source,
39-
...(this.token && { sessionToken: this.token }),
40-
...options
41-
});
40+
try {
41+
await http.sendEvent(this.baseURL, {
42+
type: event,
43+
source: this.source,
44+
...(this.token && { sessionToken: this.token }),
45+
...options
46+
});
47+
} catch(error) {
48+
this.processError(error, {
49+
message: errorsLogs.sendEvent,
50+
data: {
51+
event,
52+
source: this.source,
53+
...(this.token && { sessionToken: this.token }),
54+
...options
55+
},
56+
});
57+
}
4258
}
4359

4460
async processError(
@@ -79,27 +95,29 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
7995
case badGateway:
8096
case serviceUnavailable:
8197
case timeout:
82-
return this.connectionErrorHandler();
98+
await this.connectionErrorHandler();
8399
case unauthorizedUser:
84100
case notFound:
85101
default:
86102
await this.sendErrorToServer(error, options);
87-
return this.generalErrorHandler();
103+
await this.generalErrorHandler();
88104
}
89105
}
90106

91-
private generalErrorHandler(): void {
107+
private async generalErrorHandler(): Promise<void> {
92108
this.transientErrors = 0;
93-
setContext(DEEPCODE_CONTEXT.ERROR, DEEPCODE_ERROR_CODES.BLOCKING);
109+
await setContext(DEEPCODE_CONTEXT.ERROR, DEEPCODE_ERROR_CODES.BLOCKING);
94110
}
95111

96-
private connectionErrorHandler(): void {
112+
private async connectionErrorHandler(): Promise<void> {
97113
if (this.transientErrors > MAX_CONNECTION_RETRIES) return this.generalErrorHandler();
98114

99115
++this.transientErrors;
100-
setContext(DEEPCODE_CONTEXT.ERROR, DEEPCODE_ERROR_CODES.TRANSIENT);
101-
setTimeout(async () => {
102-
this.startExtension();
116+
await setContext(DEEPCODE_CONTEXT.ERROR, DEEPCODE_ERROR_CODES.TRANSIENT);
117+
setTimeout(() => {
118+
this.startExtension().catch((err) => this.processError(err, {
119+
message: errorsLogs.failedExecutionTransient,
120+
}));
103121
}, 5000);
104122
}
105123

@@ -131,6 +149,7 @@ abstract class ReportModule extends BaseDeepCodeModule implements DeepCode.Repor
131149
}
132150
});
133151
} catch (e) {
152+
console.error(errorsLogs.errorReportFail);
134153
console.error(e);
135154
}
136155
}

0 commit comments

Comments
 (0)