1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[PM-14180] Provide more debugging details in wasm-debug (#11771)

Improve error logging to include some additional information about the error.
This commit is contained in:
Oscar Hinton
2024-10-31 10:07:55 +01:00
committed by GitHub
parent 4de7cb8012
commit 5e157c5bca
7 changed files with 38 additions and 21 deletions

View File

@@ -1347,14 +1347,17 @@ export default class MainBackground {
if (flagEnabled("sdk")) { if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized // Warn if the SDK for some reason can't be initialized
let supported = false; let supported = false;
let error: Error;
try { try {
supported = await firstValueFrom(this.sdkService.supported$); supported = await firstValueFrom(this.sdkService.supported$);
} catch (e) { } catch (e) {
// Do nothing. error = e;
} }
if (!supported) { if (!supported) {
this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); this.sdkService
.failedToInitialize("background", error)
.catch((e) => this.logService.error(e));
} }
} }

View File

@@ -1,7 +1,7 @@
import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, inject } from "@angular/core"; import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, inject } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { NavigationEnd, Router, RouterOutlet } from "@angular/router"; import { NavigationEnd, Router, RouterOutlet } from "@angular/router";
import { Subject, takeUntil, firstValueFrom, concatMap, filter, tap, catchError, of } from "rxjs"; import { Subject, takeUntil, firstValueFrom, concatMap, filter, tap } from "rxjs";
import { LogoutReason } from "@bitwarden/auth/common"; import { LogoutReason } from "@bitwarden/auth/common";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
@@ -71,21 +71,24 @@ export class AppComponent implements OnInit, OnDestroy {
) { ) {
if (flagEnabled("sdk")) { if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized // Warn if the SDK for some reason can't be initialized
this.sdkService.supported$ this.sdkService.supported$.pipe(takeUntilDestroyed()).subscribe({
.pipe( next: (supported) => {
takeUntilDestroyed(),
catchError(() => {
return of(false);
}),
)
.subscribe((supported) => {
if (!supported) { if (!supported) {
this.logService.debug("SDK is not supported"); this.logService.debug("SDK is not supported");
this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); this.sdkService
.failedToInitialize("popup", undefined)
.catch((e) => this.logService.error(e));
} else { } else {
this.logService.debug("SDK is supported"); this.logService.debug("SDK is supported");
} }
}); },
error: (e: unknown) => {
this.sdkService
.failedToInitialize("popup", e as Error)
.catch((e) => this.logService.error(e));
this.logService.error(e);
},
});
} }
} }

View File

@@ -872,7 +872,7 @@ export class ServiceContainer {
} }
if (!supported) { if (!supported) {
this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); this.sdkService.failedToInitialize("cli").catch((e) => this.logService.error(e));
} }
} }
} }

View File

@@ -180,7 +180,7 @@ export class AppComponent implements OnInit, OnDestroy {
.subscribe((supported) => { .subscribe((supported) => {
if (!supported) { if (!supported) {
this.logService.debug("SDK is not supported"); this.logService.debug("SDK is not supported");
this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); this.sdkService.failedToInitialize("desktop").catch((e) => this.logService.error(e));
} else { } else {
this.logService.debug("SDK is supported"); this.logService.debug("SDK is supported");
} }

View File

@@ -104,7 +104,7 @@ export class AppComponent implements OnDestroy, OnInit {
.subscribe((supported) => { .subscribe((supported) => {
if (!supported) { if (!supported) {
this.logService.debug("SDK is not supported"); this.logService.debug("SDK is not supported");
this.sdkService.failedToInitialize().catch((e) => this.logService.error(e)); this.sdkService.failedToInitialize("web").catch((e) => this.logService.error(e));
} else { } else {
this.logService.debug("SDK is supported"); this.logService.debug("SDK is supported");
} }

View File

@@ -29,5 +29,5 @@ export abstract class SdkService {
*/ */
abstract userClient$(userId: UserId): Observable<BitwardenClient>; abstract userClient$(userId: UserId): Observable<BitwardenClient>;
abstract failedToInitialize(): Promise<void>; abstract failedToInitialize(category: string, error?: Error): Promise<void>;
} }

View File

@@ -130,7 +130,7 @@ export class DefaultSdkService implements SdkService {
return client$; return client$;
} }
async failedToInitialize(): Promise<void> { async failedToInitialize(category: string, error?: Error): Promise<void> {
// Only log on cloud instances // Only log on cloud instances
if ( if (
this.platformUtilsService.isDev() || this.platformUtilsService.isDev() ||
@@ -139,9 +139,20 @@ export class DefaultSdkService implements SdkService {
return; return;
} }
return this.apiService.send("POST", "/wasm-debug", null, false, false, null, (headers) => { return this.apiService.send(
headers.append("SDK-Version", "1.0.0"); "POST",
}); "/wasm-debug",
{
category: category,
error: error?.message,
},
false,
false,
null,
(headers) => {
headers.append("SDK-Version", "1.0.0");
},
);
} }
private async initializeClient( private async initializeClient(