Skip to content

Commit

Permalink
use literal values in place of Severity enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Apr 7, 2022
1 parent 978aec4 commit 28983aa
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/browser/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
/**
* @inheritDoc
*/
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
public eventFromMessage(message: string, level: Severity = 'info' as Severity, hint?: EventHint): PromiseLike<Event> {
return eventFromMessage(message, level, hint, this._options.attachStacktrace);
}

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 @@ -161,7 +161,7 @@ export function eventFromException(
const syntheticException = (hint && hint.syntheticException) || undefined;
const event = eventFromUnknownInput(exception, syntheticException, attachStacktrace);
addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
event.level = Severity.Error;
event.level = 'error' as Severity;
if (hint && hint.event_id) {
event.event_id = hint.event_id;
}
Expand All @@ -174,7 +174,7 @@ export function eventFromException(
*/
export function eventFromMessage(
message: string,
level: Severity = Severity.Info,
level: Severity = 'info' as Severity,
hint?: EventHint,
attachStacktrace?: boolean,
): PromiseLike<Event> {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function _fetchBreadcrumb(handlerData: { [key: string]: any }): void {
{
category: 'fetch',
data: handlerData.fetchData,
level: Severity.Error,
level: 'error' as Severity,
type: 'http',
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function _installGlobalOnErrorHandler(): void {
column,
);

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

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

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

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

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

Expand Down
20 changes: 10 additions & 10 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
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' as Severity);
expect((scope as any)._level).toEqual('critical' as Severity);
});

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' as Severity).setUser({ id: '1' });
expect((scope as any)._level).toEqual('critical' as Severity);
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' as Severity);
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' as Severity);
const event: Event = {};
event.level = Severity.Critical;
event.level = 'critical' as Severity;
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.level).toEqual(Severity.Warning);
expect(processedEvent!.level).toEqual('warning' as Severity);
});
});

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' as Severity);
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' as Severity);
localScope.setFingerprint(['bar']);
(localScope as any)._requestSession = { status: 'ok' };

Expand Down
12 changes: 6 additions & 6 deletions packages/minimal/test/lib/minimal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,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' as Severity);
expect(global.__SENTRY__.hub._stack[1].scope._level).toEqual('warning' as Severity);
});
});

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

test('withScope', () => {
withScope(scope => {
scope.setLevel(Severity.Warning);
scope.setLevel('warning' as Severity);
scope.setFingerprint(['1']);
withScope(scope2 => {
scope2.setLevel(Severity.Info);
scope2.setLevel('info' as Severity);
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' as Severity);
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' as Severity);
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' as Sentry.Severity,
});

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' as Sentry.Severity,
});

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' as Sentry.Severity);
Sentry.captureMessage('info_message', 'info' as Sentry.Severity);
Sentry.captureMessage('warning_message', 'warning' as Sentry.Severity);
Sentry.captureMessage('error_message', 'error' as Sentry.Severity);
Sentry.captureMessage('fatal_message', 'fatal' as Sentry.Severity);
Sentry.captureMessage('critical_message', 'critical' as Sentry.Severity);
Sentry.captureMessage('log_message', 'log' as Sentry.Severity);
2 changes: 1 addition & 1 deletion packages/node/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
/**
* @inheritDoc
*/
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
public eventFromMessage(message: string, level: Severity = 'info' as Severity, hint?: EventHint): PromiseLike<Event> {
return resolvedSyncPromise(eventFromMessage(message, level, hint, this._options.attachStacktrace));
}

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 @@ -92,7 +92,7 @@ export function eventFromUnknownInput(exception: unknown, hint?: EventHint): Eve
*/
export function eventFromMessage(
message: string,
level: Severity = Severity.Info,
level: Severity = 'info' as Severity,
hint?: EventHint,
attachStacktrace?: boolean,
): Event {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/onuncaughtexception.ts
Original file line number Diff line number Diff line change
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' as Severity);
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' as Sentry.Severity);
});
}, timeoutWarningDelay);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/severity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function isSupportedSeverity(level: string): level is Severity {
* @returns Severity
*/
export function severityFromString(level: SeverityLevel | string): Severity {
if (level === 'warn') return Severity.Warning;
if (level === 'warn') return 'warning' as Severity;
if (isSupportedSeverity(level)) {
return level;
}
return Severity.Log;
return 'log' as Severity;
}

0 comments on commit 28983aa

Please sign in to comment.