Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Deprecated `AddRequestDataToEventOptions.transaction`. This option effectively doesn't do anything anymore, and will
be removed in v9.
- Deprecated `TransactionNamingScheme` type.
- Deprecated `validSeverityLevels`. Will not be replaced.

## `@sentry/core`

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils-hoist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type {
TransactionNamingScheme,
} from './requestdata';

// eslint-disable-next-line deprecation/deprecation
export { severityLevelFromString, validSeverityLevels } from './severity';
export {
UNKNOWN_FUNCTION,
Expand Down
17 changes: 6 additions & 11 deletions packages/core/src/utils-hoist/severity.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import type { SeverityLevel } from '@sentry/types';

// Note: Ideally the `SeverityLevel` type would be derived from `validSeverityLevels`, but that would mean either
//
// a) moving `validSeverityLevels` to `@sentry/types`,
// b) moving the`SeverityLevel` type here, or
// c) importing `validSeverityLevels` from here into `@sentry/types`.
//
// Option A would make `@sentry/types` a runtime dependency of `@sentry/core` (not good), and options B and C would
// create a circular dependency between `@sentry/types` and `@sentry/core` (also not good). So a TODO accompanying the
// type, reminding anyone who changes it to change this list also, will have to do.

/**
* @deprecated This variable has been deprecated and will be removed in the next major version.
*/
export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'];

/**
Expand All @@ -19,5 +12,7 @@ export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info',
* @returns The `SeverityLevel` corresponding to the given string, or 'log' if the string isn't a valid level.
*/
export function severityLevelFromString(level: SeverityLevel | string): SeverityLevel {
return (level === 'warn' ? 'warning' : validSeverityLevels.includes(level) ? level : 'log') as SeverityLevel;
return (
level === 'warn' ? 'warning' : ['fatal', 'error', 'warning', 'log', 'info', 'debug'].includes(level) ? level : 'log'
) as SeverityLevel;
}
4 changes: 2 additions & 2 deletions packages/core/test/utils-hoist/severity.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { severityLevelFromString, validSeverityLevels } from '../../src/utils-hoist/severity';
import { severityLevelFromString } from '../../src/utils-hoist/severity';

describe('severityLevelFromString()', () => {
test("converts 'warn' to 'warning'", () => {
Expand All @@ -10,7 +10,7 @@ describe('severityLevelFromString()', () => {
});

test('acts as a pass-through for valid level strings', () => {
for (const level of validSeverityLevels) {
for (const level of ['fatal', 'error', 'warning', 'log', 'info', 'debug']) {
expect(severityLevelFromString(level)).toBe(level);
}
});
Expand Down
2 changes: 0 additions & 2 deletions packages/types/src/severity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
// Note: If this is ever changed, the `validSeverityLevels` array in `@sentry/core` needs to be changed, also. (See
// note there for why we can't derive one from the other.)
export type SeverityLevel = 'fatal' | 'error' | 'warning' | 'log' | 'info' | 'debug';
Loading