Enable lint rules for Promise handling to discourage misuse of them. (#2607)
* Enable lint rules for Promise handling to discourage misuse of them. Squashed all of Hugh's commits into one. --------- Co-authored-by: Hugh Nimmo-Smith <hughns@element.io>
This commit is contained in:
@@ -256,7 +256,7 @@ export class PosthogAnalytics {
|
||||
this.posthog.identify(analyticsID);
|
||||
} else {
|
||||
logger.info(
|
||||
"No analyticsID is availble. Should not try to setup posthog",
|
||||
"No analyticsID is available. Should not try to setup posthog",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -324,7 +324,9 @@ export class PosthogAnalytics {
|
||||
}
|
||||
|
||||
public onLoginStatusChanged(): void {
|
||||
this.maybeIdentifyUser();
|
||||
this.maybeIdentifyUser().catch(() =>
|
||||
logger.log("Could not identify user on login status change"),
|
||||
);
|
||||
}
|
||||
|
||||
private updateSuperProperties(): void {
|
||||
@@ -373,20 +375,27 @@ export class PosthogAnalytics {
|
||||
}
|
||||
}
|
||||
|
||||
public async trackEvent<E extends IPosthogEvent>(
|
||||
public trackEvent<E extends IPosthogEvent>(
|
||||
{ eventName, ...properties }: E,
|
||||
options?: CaptureOptions,
|
||||
): Promise<void> {
|
||||
): void {
|
||||
const doCapture = (): void => {
|
||||
if (
|
||||
this.anonymity == Anonymity.Disabled ||
|
||||
this.anonymity == Anonymity.Anonymous
|
||||
)
|
||||
return;
|
||||
this.capture(eventName, properties, options);
|
||||
};
|
||||
|
||||
if (this.identificationPromise) {
|
||||
// only make calls to posthog after the identificaion is done
|
||||
await this.identificationPromise;
|
||||
// only make calls to posthog after the identification is done
|
||||
this.identificationPromise.then(doCapture, (e) => {
|
||||
logger.error("Failed to identify user for tracking", e);
|
||||
});
|
||||
} else {
|
||||
doCapture();
|
||||
}
|
||||
if (
|
||||
this.anonymity == Anonymity.Disabled ||
|
||||
this.anonymity == Anonymity.Anonymous
|
||||
)
|
||||
return;
|
||||
this.capture(eventName, properties, options);
|
||||
}
|
||||
|
||||
private startListeningToSettingsChanges(): void {
|
||||
@@ -400,7 +409,9 @@ export class PosthogAnalytics {
|
||||
// won't be called (i.e. this.anonymity will be left as the default, until the setting changes)
|
||||
optInAnalytics.value.subscribe((optIn) => {
|
||||
this.setAnonymity(optIn ? Anonymity.Pseudonymous : Anonymity.Disabled);
|
||||
this.maybeIdentifyUser();
|
||||
this.maybeIdentifyUser().catch(() =>
|
||||
logger.log("Could not identify user"),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export class PosthogSpanProcessor implements SpanProcessor {
|
||||
|
||||
public onStart(span: Span): void {
|
||||
// Hack: Yield to allow attributes to be set before processing
|
||||
Promise.resolve().then(() => {
|
||||
try {
|
||||
switch (span.name) {
|
||||
case "matrix.groupCallMembership":
|
||||
this.onGroupCallMembershipStart(span);
|
||||
@@ -43,7 +43,10 @@ export class PosthogSpanProcessor implements SpanProcessor {
|
||||
this.onSummaryReportStart(span);
|
||||
return;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// log to avoid tripping @typescript-eslint/no-unused-vars
|
||||
logger.debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
public onEnd(span: ReadableSpan): void {
|
||||
@@ -148,7 +151,7 @@ export class PosthogSpanProcessor implements SpanProcessor {
|
||||
/**
|
||||
* Shutdown the processor.
|
||||
*/
|
||||
public shutdown(): Promise<void> {
|
||||
public async shutdown(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user