OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix double sending of errors
Oliver Güntheraa7d679bbc78
diff --git a/frontend/package-lock.json b/frontend/package-lock.jsonindex 1e4ae8bc4a4..f452e9d23c4 100644--- a/frontend/package-lock.json+++ b/frontend/package-lock.json@@ -2795,6 +2795,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",@@ -2813,6 +2818,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",@@ -2832,6 +2842,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",@@ -2849,6 +2864,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",@@ -2866,6 +2886,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",@@ -2885,6 +2910,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",@@ -2906,6 +2936,11 @@"tslib": "^1.9.3"},"dependencies": {+ "@sentry/types": {+ "version": "6.2.3",+ "resolved": "https://registry.npmjs.org/@sentry/types/-/types-6.2.3.tgz",+ "integrity": "sha512-BpA+9FherWgYlkMD/82bGFh/gAqZNlZX5UE8vWLKyyzNyOEEz3v9ScxE8dOSWE4v5iXJR1O3jjxaTcRQxPVgCA=="+ },"tslib": {"version": "1.14.1","resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",diff --git a/frontend/package.json b/frontend/package.jsonindex f6a28770bfb..4eceef50269 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -80,8 +80,9 @@"@ng-select/ng-option-highlight": "0.0.5","@ng-select/ng-select": "^4.0.4","@ngx-formly/core": "^5.10.19",- "@sentry/angular": "^6.2.3",- "@sentry/tracing": "^6.2.3",+ "@sentry/angular": "6.2.3",+ "@sentry/tracing": "6.2.3",+ "@sentry/types": "^6.2.3","@uirouter/angular": "^8.0.0","@uirouter/core": "^6.0.7","@uirouter/rx": "^0.6.5",diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex 002260ed63c..e8ab4dae5f0 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -27,7 +27,10 @@//++import {- APP_INITIALIZER, ApplicationRef, Injector, NgModule,+ APP_INITIALIZER,+ ApplicationRef,+ Injector,+ NgModule,} from '@angular/core';import { ReactiveFormsModule } from '@angular/forms';import { OpContextMenuTrigger } from 'core-app/shared/components/op-context-menu/handlers/op-context-menu-trigger.directive';diff --git a/frontend/src/app/core/errors/sentry/sentry-reporter.ts b/frontend/src/app/core/errors/sentry/sentry-reporter.tsindex cd84b847148..eb15fd43788 100644--- a/frontend/src/app/core/errors/sentry/sentry-reporter.ts+++ b/frontend/src/app/core/errors/sentry/sentry-reporter.ts@@ -27,9 +27,15 @@//++import {- Event as SentryEvent, Hub, Scope, Severity,+ Event as SentryEvent,+ Hub,+ Scope,+ Severity,} from '@sentry/types';import { environment } from '../../../../environments/environment';+import { EventHint } from '@sentry/angular';+import { HttpErrorResponse } from '@angular/common/http';+import { debugLog } from 'core-app/shared/helpers/debug_output';export type ScopeCallback = (scope:Scope) => void;export type MessageSeverity = 'fatal'|'error'|'warning'|'log'|'info'|'debug';@@ -55,7 +61,7 @@ export interface ErrorReporter extends CaptureInterface {interface QueuedMessage {type:'captureMessage'|'captureException';- args:any[];+ args:unknown[];}export class SentryReporter implements ErrorReporter {@@ -82,7 +88,7 @@ export class SentryReporter implements ErrorReporter {const version = sentryElement.dataset.version || 'unknown';const traceFactor = parseFloat(sentryElement.dataset.tracingFactor || '0.0');- import('./sentry-dependency').then((imported) => {+ void import('./sentry-dependency').then((imported) => {const sentry = imported.Sentry;sentry.init({dsn,@@ -114,10 +120,10 @@ export class SentryReporter implements ErrorReporter {'Non-Error exception captured with keys: $embedded, $halType, $links, $loaded',],- beforeSend: (event) => this.filterEvent(event),+ beforeSend: (event, hint) => SentryReporter.filterEvent(event, hint),});- this.sentryLoaded(sentry as any);+ this.sentryLoaded(sentry as unknown as Hub);});}@@ -127,13 +133,15 @@ export class SentryReporter implements ErrorReporter {// Send all messages from before sentry got loadedthis.messageStack.forEach((item) => {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-accessthis[item.type].bind(this).apply(item.args);});}public captureMessage(msg:string, severity:MessageSeverity = 'info'):void {if (!this.client) {- return this.handleOfflineMessage('captureMessage', [msg, severity]);+ this.handleOfflineMessage('captureMessage', [msg, severity]);+ return;}this.client.withScope((scope:Scope) => {@@ -145,11 +153,12 @@ export class SentryReporter implements ErrorReporter {public captureException(err:Error|string):void {if (!this.client || !err) {this.handleOfflineMessage('captureException', [err]);- throw err;+ throw (err as Error);}if (typeof err === 'string') {- return this.captureMessage(err, 'error');+ this.captureMessage(err, 'error');+ return;}this.client.withScope((scope:Scope) => {@@ -172,11 +181,11 @@ export class SentryReporter implements ErrorReporter {* @param type* @param args*/- private handleOfflineMessage(type:'captureMessage'|'captureException', args:any[]) {+ private handleOfflineMessage(type:'captureMessage'|'captureException', args:unknown[]) {if (this.sentryConfigured) {this.messageStack.push({ type, args });} else {- console.log('[ErrorReporter] Would queue sentry message %O %O, but is not configured.', type, args);+ debugLog('[ErrorReporter] Would queue sentry message %O %O, but is not configured.', type, args);}}@@ -199,8 +208,16 @@ export class SentryReporter implements ErrorReporter {* it from being sent.** @param event+ * @param hint*/- private filterEvent(event:SentryEvent):SentryEvent|null {+ private static filterEvent(event:SentryEvent, hint:EventHint|undefined):SentryEvent|null {+ // avoid duplicate requests on thrown angular errors, they+ // are handled by the hal error handler+ // https://github.com/getsentry/sentry-javascript/issues/2532#issuecomment-875428325+ if (hint?.originalException instanceof HttpErrorResponse) {+ return null;+ }+const unsupportedBrowser = document.body.classList.contains('-unsupported-browser');if (unsupportedBrowser) {console.warn('Browser is not supported, skipping sentry reporting completely.');diff --git a/frontend/src/app/features/hal/services/hal-aware-error-handler.ts b/frontend/src/app/features/hal/services/hal-aware-error-handler.tsindex 2bc6cefffdc..ac1d788a386 100644--- a/frontend/src/app/features/hal/services/hal-aware-error-handler.ts+++ b/frontend/src/app/features/hal/services/hal-aware-error-handler.ts@@ -1,8 +1,16 @@-import { ErrorHandler, Injectable } from '@angular/core';+import {+ ErrorHandler,+ Injectable,+} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { ErrorResource } from 'core-app/features/hal/resources/error-resource';import { HalError } from 'core-app/features/hal/services/hal-error';+import { HttpErrorResponse } from '@angular/common/http';++interface RejectedPromise {+ rejection:unknown;+}@Injectable()export class HalAwareErrorHandler extends ErrorHandler {@@ -17,9 +25,17 @@ export class HalAwareErrorHandler extends ErrorHandler {public handleError(error:unknown):void {let message:string = this.text.internal_error;+ // Angular wraps our errors into uncaught promises if+ // no one catches the error explictly. Unwrap the error in that case+ if ((error as RejectedPromise)?.rejection instanceof HalError) {+ this.handleError((error as RejectedPromise).rejection);+ return;+ }+if (error instanceof HalError) {console.error('Returned HTTP HAL error resource %O', error.message);- message += ` ${error.message}`;+ message = error.httpError?.status >= 500 ? `${message} ${error.message}` : error.message;+ HalAwareErrorHandler.captureHttpError(error.httpError);} else if (error instanceof ErrorResource) {console.error('Returned error resource %O', error);message += ` ${error.errorMessages.join('\n')}`;@@ -27,7 +43,10 @@ export class HalAwareErrorHandler extends ErrorHandler {console.error('Returned hal resource %O', error);message += `Resource returned ${error.name}`;} else if (error instanceof Error) {- window.ErrorReporter.captureException(error);+ HalAwareErrorHandler.reportError(error);+ } else if (error instanceof HttpErrorResponse) {+ HalAwareErrorHandler.captureHttpError(error);+ message = error.message;} else if (typeof error === 'string') {window.ErrorReporter.captureMessage(error);message = error;@@ -35,4 +54,19 @@ export class HalAwareErrorHandler extends ErrorHandler {super.handleError(message);}++ private static reportError(error:Error):void {+ window.ErrorReporter.captureException(error);+ }++ /**+ * Report any 5xx errors to sentry, if configured.+ * @param httpError+ * @private+ */+ private static captureHttpError(httpError:HttpErrorResponse):void {+ if (httpError.status >= 500) {+ HalAwareErrorHandler.reportError(httpError);+ }+ }}diff --git a/frontend/src/app/features/hal/services/hal-error.ts b/frontend/src/app/features/hal/services/hal-error.tsindex d77141a31d7..c744bc7c74e 100644--- a/frontend/src/app/features/hal/services/hal-error.ts+++ b/frontend/src/app/features/hal/services/hal-error.ts@@ -1,7 +1,7 @@import { HttpErrorResponse } from '@angular/common/http';import { ErrorResource } from 'core-app/features/hal/resources/error-resource';-export class HalError implements Error {+export class HalError extends Error {readonly name = 'HALError';get message():string {@@ -16,5 +16,7 @@ export class HalError implements Error {readonly httpError:HttpErrorResponse,readonly resource:ErrorResource,) {+ super();+ Object.setPrototypeOf(this, HalError.prototype);}}