Skip to content

Commit

Permalink
replace uses of Severity enum with equivalent strings
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Apr 12, 2022
1 parent 925d5a8 commit 7e4e2de
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class BrowserClient extends BaseClient<BrowserOptions> {
*/
public eventFromMessage(
message: string,
level: Severity | SeverityLevel = Severity.Info,
level: Severity | SeverityLevel = 'info',
hint?: EventHint,
): PromiseLike<Event> {
return eventFromMessage(
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function eventFromException(
const syntheticException = (hint && hint.syntheticException) || undefined;
const event = eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace);
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
event.level = Severity.Error;
event.level = 'error';
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
Expand All @@ -164,7 +164,7 @@ export function eventFromException(
export function eventFromMessage(
stackParser: StackParser,
message: string,
level: Severity | SeverityLevel = Severity.Info,
level: Severity | SeverityLevel = 'info',
hint?: EventHint,
attachStacktrace?: boolean,
): PromiseLike<Event> {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable max-lines */
import { getCurrentHub } from '@sentry/core';
import { Event, Integration, Severity } from '@sentry/types';
import { Event, Integration } from '@sentry/types';
import {
addInstrumentationHandler,
getEventDescription,
Expand Down Expand Up @@ -230,7 +230,7 @@ function _fetchBreadcrumb(handlerData: { [key: string]: any }): void {
{
category: 'fetch',
data: handlerData.fetchData,
level: Severity.Error,
level: 'error',
type: 'http',
},
{
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { getCurrentHub } from '@sentry/core';
import { Event, EventHint, Hub, Integration, Primitive, Severity, StackParser } from '@sentry/types';
import { Event, EventHint, Hub, Integration, Primitive, StackParser } from '@sentry/types';
import {
addExceptionMechanism,
addInstrumentationHandler,
Expand Down Expand Up @@ -100,7 +100,7 @@ function _installGlobalOnErrorHandler(): void {
column,
);

event.level = Severity.Error;
event.level = 'error';

addMechanismAndCapture(hub, error, event, 'onerror');
},
Expand Down Expand Up @@ -146,7 +146,7 @@ function _installGlobalOnUnhandledRejectionHandler(): void {
? _eventFromRejectionWithPrimitive(error)
: eventFromUnknownInput(stackParser, error, undefined, attachStacktrace, true);

event.level = Severity.Error;
event.level = 'error';

addMechanismAndCapture(hub, error, event, 'onunhandledrejection');
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/mocks/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class TestClient extends BaseClient<TestOptions> {
});
}

public eventFromMessage(message: string, level: Severity | SeverityLevel = Severity.Info): PromiseLike<Event> {
public eventFromMessage(message: string, level: Severity | SeverityLevel = 'info'): PromiseLike<Event> {
return resolvedSyncPromise({ message, level });
}

Expand Down
22 changes: 11 additions & 11 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event, EventHint, Severity } from '@sentry/types';
import { Event, EventHint } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils';

import { addGlobalEventProcessor, Scope } from '../src';
Expand Down Expand Up @@ -85,8 +85,8 @@ describe('Scope', () => {

test('setLevel', () => {
const scope = new Scope();
scope.setLevel(Severity.Critical);
expect((scope as any)._level).toEqual(Severity.Critical);
scope.setLevel('critical');
expect((scope as any)._level).toEqual('critical');
});

test('setTransactionName', () => {
Expand Down Expand Up @@ -137,8 +137,8 @@ describe('Scope', () => {

test('chaining', () => {
const scope = new Scope();
scope.setLevel(Severity.Critical).setUser({ id: '1' });
expect((scope as any)._level).toEqual(Severity.Critical);
scope.setLevel('critical').setUser({ id: '1' });
expect((scope as any)._level).toEqual('critical');
expect((scope as any)._user).toEqual({ id: '1' });
});
});
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('Scope', () => {
scope.setTag('a', 'b');
scope.setUser({ id: '1' });
scope.setFingerprint(['abcd']);
scope.setLevel(Severity.Warning);
scope.setLevel('warning');
scope.setTransactionName('/abc');
scope.addBreadcrumb({ message: 'test' });
scope.setContext('os', { id: '1' });
Expand Down Expand Up @@ -294,11 +294,11 @@ describe('Scope', () => {
test('scope level should have priority over event level', () => {
expect.assertions(1);
const scope = new Scope();
scope.setLevel(Severity.Warning);
scope.setLevel('warning');
const event: Event = {};
event.level = Severity.Critical;
event.level = 'critical';
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.level).toEqual(Severity.Warning);
expect(processedEvent!.level).toEqual('warning');
});
});

Expand Down Expand Up @@ -410,7 +410,7 @@ describe('Scope', () => {
scope.setContext('foo', { id: '1' });
scope.setContext('bar', { id: '2' });
scope.setUser({ id: '1337' });
scope.setLevel(Severity.Info);
scope.setLevel('info');
scope.setFingerprint(['foo']);
scope.setRequestSession({ status: 'ok' });
});
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('Scope', () => {
localScope.setContext('bar', { id: '3' });
localScope.setContext('baz', { id: '4' });
localScope.setUser({ id: '42' });
localScope.setLevel(Severity.Warning);
localScope.setLevel('warning');
localScope.setFingerprint(['bar']);
(localScope as any)._requestSession = { status: 'ok' };

Expand Down
13 changes: 6 additions & 7 deletions packages/minimal/test/lib/minimal.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getCurrentHub, getHubFromCarrier, Scope } from '@sentry/hub';
import { Severity } from '@sentry/types';

import {
_callOnClient,
Expand Down Expand Up @@ -165,8 +164,8 @@ describe('Minimal', () => {
const client: any = new TestClient({});
const scope = getCurrentHub().pushScope();
getCurrentHub().bindClient(client);
scope.setLevel(Severity.Warning);
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual(Severity.Warning);
scope.setLevel('warning');
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual('warning');
});
});

Expand Down Expand Up @@ -245,16 +244,16 @@ describe('Minimal', () => {

test('withScope', () => {
withScope(scope => {
scope.setLevel(Severity.Warning);
scope.setLevel('warning');
scope.setFingerprint(['1']);
withScope(scope2 => {
scope2.setLevel(Severity.Info);
scope2.setLevel('info');
scope2.setFingerprint(['2']);
withScope(scope3 => {
scope3.clear();
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual(Severity.Warning);
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual('warning');
expect(global.__SENTRY__.hub._stack[1].scope._fingerprint).toEqual(['1']);
expect(global.__SENTRY__.hub._stack[2].scope._level).toEqual(Severity.Info);
expect(global.__SENTRY__.hub._stack[2].scope._level).toEqual('info');
expect(global.__SENTRY__.hub._stack[2].scope._fingerprint).toEqual(['2']);
expect(global.__SENTRY__.hub._stack[3].scope._level).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Sentry.init({
Sentry.addBreadcrumb({
category: 'foo',
message: 'bar',
level: Sentry.Severity.Critical,
level: 'critical',
});

Sentry.addBreadcrumb({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Sentry.init({
Sentry.addBreadcrumb({
category: 'foo',
message: 'bar',
level: Sentry.Severity.Critical,
level: 'critical',
});

Sentry.captureMessage('test_simple');
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Sentry.init({
release: '1.0',
});

Sentry.captureMessage('debug_message', Sentry.Severity.Debug);
Sentry.captureMessage('info_message', Sentry.Severity.Info);
Sentry.captureMessage('warning_message', Sentry.Severity.Warning);
Sentry.captureMessage('error_message', Sentry.Severity.Error);
Sentry.captureMessage('fatal_message', Sentry.Severity.Fatal);
Sentry.captureMessage('critical_message', Sentry.Severity.Critical);
Sentry.captureMessage('log_message', Sentry.Severity.Log);
Sentry.captureMessage('debug_message', 'debug');
Sentry.captureMessage('info_message', 'info');
Sentry.captureMessage('warning_message', 'warning');
Sentry.captureMessage('error_message', 'error');
Sentry.captureMessage('fatal_message', 'fatal');
Sentry.captureMessage('critical_message', 'critical');
Sentry.captureMessage('log_message', 'log');
2 changes: 1 addition & 1 deletion packages/node/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class NodeClient extends BaseClient<NodeOptions> {
*/
public eventFromMessage(
message: string,
level: Severity | SeverityLevel = Severity.Info,
level: Severity | SeverityLevel = 'info',
hint?: EventHint,
): PromiseLike<Event> {
return resolvedSyncPromise(
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function eventFromUnknownInput(stackParser: StackParser, exception: unkno
export function eventFromMessage(
stackParser: StackParser,
message: string,
level: Severity | SeverityLevel = Severity.Info,
level: Severity | SeverityLevel = 'info',
hint?: EventHint,
attachStacktrace?: boolean,
): Event {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/onuncaughtexception.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentHub, Scope } from '@sentry/core';
import { Integration, Severity } from '@sentry/types';
import { Integration } from '@sentry/types';
import { logger } from '@sentry/utils';

import { NodeClient } from '../client';
Expand Down Expand Up @@ -78,7 +78,7 @@ export class OnUncaughtException implements Integration {

if (hub.getIntegration(OnUncaughtException)) {
hub.withScope((scope: Scope) => {
scope.setLevel(Severity.Fatal);
scope.setLevel('fatal');
hub.captureException(error, {
originalException: error,
data: { mechanism: { handled: false, type: 'onuncaughtexception' } },
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export function wrapHandler<TEvent, TResult>(
timeoutWarningTimer = setTimeout(() => {
withScope(scope => {
scope.setTag('timeout', humanReadableTimeout);
captureMessage(`Possible function timeout: ${context.functionName}`, Sentry.Severity.Warning);
captureMessage(`Possible function timeout: ${context.functionName}`, 'warning');
});
}, timeoutWarningDelay);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/severity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info',
* @returns Severity
*/
export function severityFromString(level: SeverityLevel | string): Severity {
return (level === 'warn' ? Severity.Warning : validSeverityLevels.includes(level) ? level : Severity.Log) as Severity;
return (level === 'warn' ? 'warning' : validSeverityLevels.includes(level) ? level : 'log') as Severity;
}

// TODO Is this necessary?
Expand Down

0 comments on commit 7e4e2de

Please sign in to comment.