Skip to content

Commit 605b9c4

Browse files
committed
compile with strict mode
1 parent e9f4580 commit 605b9c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3713
-12518
lines changed

‎.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"eslintignore",
2525
"jsdelivr",
2626
"lage",
27+
"localstorage",
2728
"maxcdn",
2829
"ncaught",
2930
"npmrc",

‎package-lock.json

+3,512-12,326
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
"example/*"
2929
],
3030
"devDependencies": {
31-
"@typescript-eslint/eslint-plugin": "4.25.0",
32-
"@typescript-eslint/parser": "4.25.0",
31+
"@typescript-eslint/eslint-plugin": "4.26.0",
32+
"@typescript-eslint/parser": "4.26.0",
3333
"eslint": "7.27.0",
3434
"eslint-plugin-eslint-comments": "3.2.0",
3535
"eslint-plugin-eslint-plugin": "3.0.3",
36-
"eslint-plugin-import": "2.23.3",
36+
"eslint-plugin-import": "2.23.4",
3737
"eslint-plugin-jest": "24.3.6",
38-
"eslint-plugin-jsdoc": "35.0.0",
38+
"eslint-plugin-jsdoc": "35.1.2",
3939
"lage": "^0.29.3",
4040
"rimraf": "3.0.2",
41-
"typescript": "4.2.4"
41+
"typescript": "4.3.2"
4242
}
4343
}

‎packages/angularjs/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"rootDir": "src"
5+
"rootDir": "src",
6+
"strict": false
67
},
78
"include": ["src"],
89
"types": ["angular", "angular-mock"]

‎packages/browser/src/plugins/BrowserErrorPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class BrowserErrorPlugin implements IEventPlugin {
2424
if (exception) {
2525
context.event.type = "error";
2626

27-
if (!context.event.data[KnownEventDataKeys.Error]) {
27+
if (context.event.data && !context.event.data[KnownEventDataKeys.Error]) {
2828
const result = await this.parse(exception);
2929
if (result) {
3030
const exclusions = context.client.config.dataExclusions.concat(IgnoredErrorProperties);

‎packages/browser/src/plugins/BrowserGlobalHandlerPlugin.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
1010
public priority: number = 100;
1111
public name: string = "BrowserGlobalHandlerPlugin";
1212

13-
private _client: ExceptionlessClient = null;
13+
private _client: ExceptionlessClient | undefined;
1414

1515
public startup(context: PluginContext): Promise<void> {
1616
if (this._client) {
@@ -21,7 +21,7 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
2121

2222
// TODO: Discus if we want to unwire this handler in suspend?
2323
window.addEventListener("error", event => {
24-
void this._client.submitUnhandledException(this.getError(event), "onerror");
24+
void this._client?.submitUnhandledException(this.getError(event), "onerror");
2525
});
2626

2727
window.addEventListener("unhandledrejection", event => {
@@ -35,18 +35,18 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
3535
// eslint-disable-next-line no-empty
3636
} catch (ex) { }
3737

38-
void this._client.submitUnhandledException(error, "onunhandledrejection");
38+
void this._client?.submitUnhandledException(error, "onunhandledrejection");
3939
});
4040

4141

4242
if (typeof $ !== "undefined" && $(document)) {
4343
$(document).ajaxError((event: Event, xhr: { responseText: string, status: number }, settings: { data: unknown, url: string }, error: string) => {
4444
if (xhr.status === 404) {
4545
// TODO: Handle async
46-
void this._client.submitNotFound(settings.url);
46+
void this._client?.submitNotFound(settings.url);
4747
} else if (xhr.status !== 401) {
4848
// TODO: Handle async
49-
void this._client.createUnhandledException(new Error(error), "JQuery.ajaxError")
49+
void this._client?.createUnhandledException(new Error(error), "JQuery.ajaxError")
5050
.setSource(settings.url)
5151
.setProperty("status", xhr.status)
5252
.setProperty("request", settings.data)
@@ -69,12 +69,15 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
6969
let msg: string = message || event.error;
7070
if (msg) {
7171
const errorNameRegex: RegExp = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Aggregate|Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
72-
const [_, errorName, errorMessage] = errorNameRegex.exec(msg);
73-
if (errorName) {
74-
name = errorName;
75-
}
76-
if (errorMessage) {
77-
msg = errorMessage;
72+
const regexResult = errorNameRegex.exec(msg);
73+
if (regexResult) {
74+
const [_, errorName, errorMessage] = regexResult;
75+
if (errorName) {
76+
name = errorName;
77+
}
78+
if (errorMessage) {
79+
msg = errorMessage;
80+
}
7881
}
7982
}
8083

‎packages/browser/src/plugins/BrowserLifeCyclePlugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class BrowserLifeCyclePlugin implements IEventPlugin {
88
public priority: number = 105;
99
public name: string = "BrowserLifeCyclePlugin";
1010

11-
private _client: ExceptionlessClient = null;
11+
private _client: ExceptionlessClient | undefined;
1212

1313
public startup(context: PluginContext): Promise<void> {
1414
if (this._client) {
@@ -17,12 +17,12 @@ export class BrowserLifeCyclePlugin implements IEventPlugin {
1717

1818
this._client = context.client;
1919

20-
globalThis.addEventListener("beforeunload", () => void this._client.suspend());
20+
globalThis.addEventListener("beforeunload", () => void this._client?.suspend());
2121
document.addEventListener("visibilitychange", () => {
2222
if (document.visibilityState === 'visible') {
23-
void this._client.startup()
23+
void this._client?.startup()
2424
} else {
25-
void this._client.suspend()
25+
void this._client?.suspend()
2626
}
2727
});
2828

‎packages/browser/src/plugins/BrowserModuleInfoPlugin.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
export class BrowserModuleInfoPlugin implements IEventPlugin {
1212
public priority: number = 50;
1313
public name: string = "BrowserModuleInfoPlugin";
14-
private _modules: ModuleInfo[] = null;
14+
private _modules: ModuleInfo[] | undefined;
1515

1616
public startup(context: PluginContext): Promise<void> {
1717
if (!this._modules) {
@@ -22,17 +22,17 @@ export class BrowserModuleInfoPlugin implements IEventPlugin {
2222
}
2323

2424
public run(context: EventPluginContext): Promise<void> {
25-
const error = context.event.data[KnownEventDataKeys.Error];
26-
if (this._modules?.length > 0 && !error?.modules) {
25+
const error = context.event.data?.[KnownEventDataKeys.Error];
26+
if (error && !error?.modules && this._modules?.length) {
2727
error.modules = this._modules;
2828
}
2929

3030
return Promise.resolve();
3131
}
3232

33-
private getModules(): ModuleInfo[] {
33+
private getModules(): ModuleInfo[] | undefined {
3434
if (!document || !document.getElementsByTagName) {
35-
return null;
35+
return;
3636
}
3737

3838
const modules: ModuleInfo[] = [];
@@ -44,7 +44,7 @@ export class BrowserModuleInfoPlugin implements IEventPlugin {
4444
modules.push({
4545
module_id: index,
4646
name: scripts[index].src.split("?")[0],
47-
version: parseVersion(scripts[index].src),
47+
version: <string>parseVersion(scripts[index].src),
4848
});
4949
} else if (scripts[index].innerHTML) {
5050
modules.push({

‎packages/browser/src/plugins/BrowserRequestInfoPlugin.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
1313
public name: string = "BrowserRequestInfoPlugin";
1414

1515
public run(context: EventPluginContext): Promise<void> {
16-
if (!context.event.data[KnownEventDataKeys.RequestInfo]) {
17-
const requestInfo: RequestInfo = this.getRequestInfo(context);
16+
if (context.event.data && !context.event.data[KnownEventDataKeys.RequestInfo]) {
17+
const requestInfo: RequestInfo | undefined = this.getRequestInfo(context);
1818
if (requestInfo) {
1919
if (isMatch(requestInfo.user_agent, context.client.config.userAgentBotPatterns)) {
2020
context.log.info("Cancelling event as the request user agent matches a known bot pattern");
@@ -28,9 +28,9 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
2828
return Promise.resolve();
2929
}
3030

31-
private getRequestInfo(context: EventPluginContext): RequestInfo {
31+
private getRequestInfo(context: EventPluginContext): RequestInfo | undefined {
3232
if (!document || !navigator || !location) {
33-
return null;
33+
return;
3434
}
3535

3636
const config = context.client.config;
@@ -47,7 +47,7 @@ export class BrowserRequestInfoPlugin implements IEventPlugin {
4747
};
4848

4949
if (config.includeCookies) {
50-
requestInfo.cookies = getCookies(document.cookie, exclusions);
50+
requestInfo.cookies = getCookies(document.cookie, exclusions) as Record<string, string>;
5151
}
5252

5353
if (config.includeQueryString) {

‎packages/browser/src/plugins/BrowserWrapFunctions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class BrowserWrapFunctions implements IEventPlugin {
88
public priority: number = 110;
99
public name: string = "BrowserWrapFunctions";
1010

11-
private _client: ExceptionlessClient = null;
11+
private _client: ExceptionlessClient | undefined;
1212

1313
public startup(context: PluginContext): Promise<void> {
1414
if (this._client) {

‎packages/browser/test/plugins/BrowserErrorPlugin.test.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import {
33
ErrorInfo,
44
Event,
5+
EventContext,
56
EventPluginContext,
67
ExceptionlessClient,
78
KnownEventDataKeys
89
} from "@exceptionless/core";
910

1011
import { CapturedExceptions } from "./../../../core/test/plugins/default/exceptions.js";
11-
1212
import { BrowserErrorPlugin } from "../../src/plugins/BrowserErrorPlugin.js";
1313

1414
function BaseTestError() {
@@ -30,19 +30,20 @@ describe("BrowserErrorPlugin", () => {
3030

3131
beforeEach(() => {
3232
plugin.parse = (exception: Error): Promise<ErrorInfo> => {
33-
return Promise.resolve({
33+
return Promise.resolve(<ErrorInfo>{
3434
type: exception.name,
3535
message: exception.message,
36-
stack_trace: null
37-
})
36+
stack_trace: undefined,
37+
modules: undefined
38+
});
3839
};
3940

4041
const client: ExceptionlessClient = new ExceptionlessClient();
4142
const event: Event = {
4243
data: {}
4344
};
4445

45-
context = new EventPluginContext(client, event);
46+
context = new EventPluginContext(client, event, new EventContext());
4647
});
4748

4849
function processError(error: Error | string | unknown): Promise<void> {
@@ -68,22 +69,22 @@ describe("BrowserErrorPlugin", () => {
6869
await processError(error);
6970
const additionalData = getAdditionalData(context.event);
7071
expect(additionalData).not.toBeNull();
71-
expect(additionalData.someProperty).toBe("Test");
72+
expect(additionalData?.someProperty).toBe("Test");
7273
});
7374

7475
test("should support custom exception types", async () => {
7576
await processError(new BaseTestError());
7677
const additionalData = getAdditionalData(context.event);
7778
expect(additionalData).not.toBeNull();
78-
expect(additionalData.someProperty).toBe("Test");
79+
expect(additionalData?.someProperty).toBe("Test");
7980
});
8081

8182
test("should support inherited properties", async () => {
8283
await processError(new DerivedTestError());
8384
const additionalData = getAdditionalData(context.event);
8485
expect(additionalData).not.toBeNull();
85-
expect(additionalData.someProperty).toBe("Test");
86-
expect(additionalData.someOtherProperty).toBe("Test2");
86+
expect(additionalData?.someProperty).toBe("Test");
87+
expect(additionalData?.someOtherProperty).toBe("Test2");
8788
});
8889

8990
test("shouldn't set empty additional data", async () => {
@@ -113,13 +114,13 @@ function describeForCapturedExceptions(specDefinitions: (exception: any) => void
113114
});
114115
}
115116

116-
function getError(event: Event): ErrorInfo {
117+
function getError(event: Event): ErrorInfo | undefined {
117118
return event?.data?.[KnownEventDataKeys.Error];
118119
}
119120

120-
function getAdditionalData(event: Event): any {
121+
function getAdditionalData(event: Event): Record<string, unknown> | undefined {
121122
const error = getError(event);
122-
return error?.data?.["@ext"];
123+
return error?.data?.["@ext"] as Record<string, unknown>;
123124
}
124125

125126
function throwAndCatch(error: Error | string | unknown): Error {

‎packages/core/src/EventBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class EventBuilder {
164164
}
165165

166166
public addTags(...tags: string[]): EventBuilder {
167-
this.target.tags = [...this.target.tags, ...tags];
167+
this.target.tags = [...this.target.tags || [], ...tags];
168168
return this;
169169
}
170170

‎packages/core/src/ExceptionlessClient.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class ExceptionlessClient {
117117

118118
public createLog(message: string): EventBuilder;
119119
public createLog(source: string, message: string): EventBuilder;
120-
public createLog(source: string, message: string, level: string): EventBuilder;
120+
public createLog(source: string | undefined, message: string, level: string): EventBuilder;
121121
public createLog(sourceOrMessage: string, message?: string, level?: string): EventBuilder {
122122
let builder = this.createEvent().setType("log");
123123

@@ -147,9 +147,9 @@ export class ExceptionlessClient {
147147

148148
public submitLog(message: string): Promise<EventPluginContext>;
149149
public submitLog(source: string, message: string): Promise<EventPluginContext>;
150-
public submitLog(source: string, message: string, level: string): Promise<EventPluginContext>;
150+
public submitLog(source: string | undefined, message: string, level: string): Promise<EventPluginContext>;
151151
public submitLog(sourceOrMessage: string, message?: string, level?: string): Promise<EventPluginContext> {
152-
return this.createLog(sourceOrMessage, message, level).submit();
152+
return this.createLog(sourceOrMessage, <string>message, <string>level).submit();
153153
}
154154

155155
public createNotFound(resource: string): EventBuilder {
@@ -203,16 +203,16 @@ export class ExceptionlessClient {
203203
* @param context Contextual data used by event plugins to enrich the event details
204204
*/
205205
public async submitEvent(event: Event, context?: EventContext): Promise<EventPluginContext> {
206-
const pluginContext = new EventPluginContext(this, event, context);
206+
const pluginContext = new EventPluginContext(this, event, context ?? new EventContext());
207207

208208
if (!event) {
209-
context.cancelled = true;
209+
pluginContext.cancelled = true;
210210
return pluginContext;
211211
}
212212

213213
if (!this.config.enabled || !this.config.isValid) {
214214
this.config.services.log.info("Event submission is currently disabled.");
215-
context.cancelled = true;
215+
pluginContext.cancelled = true;
216216
return pluginContext;
217217
}
218218

@@ -225,7 +225,7 @@ export class ExceptionlessClient {
225225
}
226226

227227
await EventPluginManager.run(pluginContext);
228-
if (context.cancelled) {
228+
if (pluginContext.cancelled) {
229229
return pluginContext;
230230
}
231231

@@ -258,19 +258,12 @@ export class ExceptionlessClient {
258258
* @param callback The submission response.
259259
*/
260260
public async updateUserEmailAndDescription(referenceId: string, email: string, description: string): Promise<void> {
261-
if (
262-
!referenceId || !email || !description || !this.config.enabled ||
263-
!this.config.isValid
264-
) {
261+
if (!referenceId || !email || !description || !this.config.enabled || !this.config.isValid) {
265262
return;
266263
}
267264

268-
const userDescription: UserDescription = {
269-
email_address: email,
270-
description,
271-
};
272-
const response = await this.config.services.submissionClient
273-
.submitUserDescription(referenceId, userDescription);
265+
const userDescription: UserDescription = { email_address: email, description };
266+
const response = await this.config.services.submissionClient.submitUserDescription(referenceId, userDescription);
274267
if (!response.success) {
275268
this.config.services.log.error(
276269
`Failed to submit user email and description for event "${referenceId}": ${response.status} ${response.message}`,

0 commit comments

Comments
 (0)