Skip to content

Commit

Permalink
switch to console error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed May 16, 2023
1 parent 78468e3 commit de3e675
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/test/lib/base.test.ts
Expand Up @@ -77,7 +77,7 @@ describe('BaseClient', () => {
expect(client.getTransport()).toBeUndefined();
});

test('allows being passed an invalid Dsn', () => {
test('handles being passed an invalid Dsn', () => {
const options = getDefaultTestClientOptions({ dsn: 'abc' });
const client = new TestClient(options);

Expand Down
5 changes: 3 additions & 2 deletions packages/utils/src/dsn.ts
@@ -1,6 +1,5 @@
import type { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';

import { SentryError } from './error';
import { logger } from './logger';

/** Regular expression used to parse a Dsn. */
Expand Down Expand Up @@ -37,7 +36,9 @@ export function dsnFromString(str: string): DsnComponents | undefined {
const match = DSN_REGEX.exec(str);

if (!match) {
logger.error(`Invalid Sentry Dsn: ${str}`);
// This should be logged to the console
// eslint-disable-next-line no-console
console.error(`Invalid Sentry Dsn: ${str}`);
return undefined;
}

Expand Down
16 changes: 9 additions & 7 deletions packages/utils/test/dsn.test.ts
Expand Up @@ -5,11 +5,12 @@ function testIf(condition: boolean): jest.It {
return condition ? test : test.skip;
}

const loggerSpy = jest.spyOn(logger, 'error').mockImplementation(() => {});
const loggerErrorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {});
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

describe('Dsn', () => {
beforeEach(() => {
loggerSpy.mockClear();
jest.clearAllMocks();
});

describe('fromComponents', () => {
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('Dsn', () => {
}),
).toBeUndefined();

expect(logger.error).toHaveBeenCalledTimes(4);
expect(loggerErrorSpy).toHaveBeenCalledTimes(4);
});

testIf(__DEBUG_BUILD__)('returns `undefined` if components are invalid', () => {
Expand All @@ -103,7 +104,7 @@ describe('Dsn', () => {
}),
).toBeUndefined();

expect(logger.error).toHaveBeenCalledTimes(2);
expect(loggerErrorSpy).toHaveBeenCalledTimes(2);
});
});

Expand Down Expand Up @@ -165,22 +166,23 @@ describe('Dsn', () => {

testIf(__DEBUG_BUILD__)('returns undefined when provided invalid Dsn', () => {
expect(makeDsn('some@random.dsn')).toBeUndefined();
expect(logger.error).toHaveBeenCalledTimes(1);
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
});

testIf(__DEBUG_BUILD__)('returns undefined if mandatory fields are missing', () => {
expect(makeDsn('://abc@sentry.io/123')).toBeUndefined();
expect(makeDsn('https://@sentry.io/123')).toBeUndefined();
expect(makeDsn('https://abc@123')).toBeUndefined();
expect(makeDsn('https://abc@sentry.io/')).toBeUndefined();
expect(logger.error).toHaveBeenCalledTimes(4);
expect(consoleErrorSpy).toHaveBeenCalledTimes(4);
});

testIf(__DEBUG_BUILD__)('returns undefined if fields are invalid', () => {
expect(makeDsn('httpx://abc@sentry.io/123')).toBeUndefined();
expect(makeDsn('httpx://abc@sentry.io:xxx/123')).toBeUndefined();
expect(makeDsn('http://abc@sentry.io/abc')).toBeUndefined();
expect(logger.error).toHaveBeenCalledTimes(3);
expect(loggerErrorSpy).toHaveBeenCalledTimes(2);
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
});
});

Expand Down

0 comments on commit de3e675

Please sign in to comment.