Skip to content

Backport SvelteKit and Angular fixes to v7 #10619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions packages/angular-ivy/scripts/prepack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type PackageJson = {
type?: string;
nx?: string;
volta?: any;
exports?: Record<string, string | Record<string, string>>;
};

const buildDir = path.join(process.cwd(), 'build');
Expand All @@ -18,6 +19,18 @@ const pkgJson: PackageJson = JSON.parse(fs.readFileSync(pkjJsonPath).toString())
delete pkgJson.main;
pkgJson.type = 'module';

pkgJson.exports = {
'.': {
es2015: './fesm2015/sentry-angular-ivy.js',
esm2015: './esm2015/sentry-angular-ivy.js',
fesm2015: './fesm2015/sentry-angular-ivy.js',
import: './fesm2015/sentry-angular-ivy.js',
require: './bundles/sentry-angular-ivy.umd.js',
types: './sentry-angular-ivy.d.ts',
},
'./*': './*',
};

// no need to keep around other properties that are only relevant for our reop:
delete pkgJson.nx;
delete pkgJson.volta;
Expand Down
8 changes: 6 additions & 2 deletions packages/sveltekit/src/client/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addNonEnumerableProperty, objectify } from '@sentry/utils';
import type { LoadEvent } from '@sveltejs/kit';

import type { SentryWrappedFlag } from '../common/utils';
import { isRedirect } from '../common/utils';
import { isHttpError, isRedirect } from '../common/utils';

type PatchedLoadEvent = LoadEvent & Partial<SentryWrappedFlag>;

Expand All @@ -14,7 +14,11 @@ function sendErrorToSentry(e: unknown): unknown {
const objectifiedErr = objectify(e);

// We don't want to capture thrown `Redirect`s as these are not errors but expected behaviour
if (isRedirect(objectifiedErr)) {
// Neither 4xx errors, given that they are not valuable.
if (
isRedirect(objectifiedErr) ||
(isHttpError(objectifiedErr) && objectifiedErr.status < 500 && objectifiedErr.status >= 400)
) {
return objectifiedErr;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/sveltekit/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function makeCustomSentryVitePlugin(options?: CustomSentryVitePlugi
// eslint-disable-next-line no-console
debug && console.log('[Source Maps Plugin] Flattening source maps');

jsFiles.forEach(async file => {
for (const file of jsFiles) {
try {
await (sorcery as Sorcery).load(file).then(async chain => {
if (!chain) {
Expand Down Expand Up @@ -202,7 +202,7 @@ export async function makeCustomSentryVitePlugin(options?: CustomSentryVitePlugi
);
await fs.promises.writeFile(mapFile, cleanedMapContent);
}
});
}

try {
// @ts-expect-error - this hook exists on the plugin!
Expand Down
24 changes: 24 additions & 0 deletions packages/sveltekit/test/client/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ describe('wrapLoadWithSentry', () => {
expect(mockCaptureException).not.toHaveBeenCalled();
});

it.each([400, 404, 499])("doesn't call captureException for thrown `HttpError`s with status %s", async status => {
async function load(_: Parameters<Load>[0]): Promise<ReturnType<Load>> {
throw { status, body: 'error' };
}

const wrappedLoad = wrapLoadWithSentry(load);
const res = wrappedLoad(MOCK_LOAD_ARGS);
await expect(res).rejects.toThrow();

expect(mockCaptureException).not.toHaveBeenCalled();
});

it.each([500, 501, 599])('calls captureException for thrown `HttpError`s with status %s', async status => {
async function load(_: Parameters<Load>[0]): Promise<ReturnType<Load>> {
throw { status, body: 'error' };
}

const wrappedLoad = wrapLoadWithSentry(load);
const res = wrappedLoad(MOCK_LOAD_ARGS);
await expect(res).rejects.toThrow();

expect(mockCaptureException).toHaveBeenCalledTimes(1);
});

describe('calls trace function', async () => {
it('creates a load span', async () => {
async function load({ params }: Parameters<Load>[0]): Promise<ReturnType<Load>> {
Expand Down