Skip to content

Commit

Permalink
feat(core): Deprecate validSeverityLevels (#14407)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Nov 22, 2024
1 parent fc79e97 commit 1b0382e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
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.
- Deprecated `urlEncode`. No replacements.
- Deprecated `arrayify`. No replacements.

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 @@ -85,6 +85,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';
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export {
winterCGHeadersToDict,
winterCGRequestToRequestData,
severityLevelFromString,
// eslint-disable-next-line deprecation/deprecation
validSeverityLevels,
UNKNOWN_FUNCTION,
createStackParser,
Expand Down

0 comments on commit 1b0382e

Please sign in to comment.