Skip to content

Commit 46988f3

Browse files
lforstZen-cronic
authored andcommitted
fix(deno): Don't rely on Deno.permissions.querySync (getsentry#13378)
1 parent 601a6bf commit 46988f3

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

packages/deno/src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { SDK_VERSION, ServerRuntimeClient } from '@sentry/core';
44
import type { DenoClientOptions } from './types';
55

66
function getHostName(): string | undefined {
7+
// Deno.permissions.querySync is not available on Deno Deploy
8+
if (!Deno.permissions.querySync) {
9+
return undefined;
10+
}
11+
712
const result = Deno.permissions.querySync({ name: 'sys', kind: 'hostname' });
813
return result.state === 'granted' ? Deno.hostname() : undefined;
914
}

packages/deno/src/integrations/context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function getOSName(): string {
1616
}
1717
}
1818

19-
function getOSRelease(): string | undefined {
20-
return Deno.permissions.querySync({ name: 'sys', kind: 'osRelease' }).state === 'granted'
19+
async function getOSRelease(): Promise<string | undefined> {
20+
return (await Deno.permissions.query({ name: 'sys', kind: 'osRelease' })).state === 'granted'
2121
? Deno.osRelease()
2222
: undefined;
2323
}
@@ -35,7 +35,7 @@ async function addDenoRuntimeContext(event: Event): Promise<Event> {
3535
},
3636
os: {
3737
name: getOSName(),
38-
version: getOSRelease(),
38+
version: await getOSRelease(),
3939
},
4040
v8: {
4141
name: 'v8',

packages/deno/src/integrations/normalizepaths.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ function appRootFromErrorStack(error: Error): string | undefined {
4242
}
4343

4444
function getCwd(): string | undefined {
45+
// Deno.permissions.querySync is not available on Deno Deploy
46+
if (!Deno.permissions.querySync) {
47+
return undefined;
48+
}
49+
4550
// We don't want to prompt for permissions so we only get the cwd if
4651
// permissions are already granted
4752
const permission = Deno.permissions.querySync({ name: 'read', path: './' });

packages/deno/src/transports/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createTransport } from '@sentry/core';
22
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
3-
import { consoleSandbox, rejectedSyncPromise } from '@sentry/utils';
3+
import { consoleSandbox, logger, rejectedSyncPromise } from '@sentry/utils';
44

55
export interface DenoTransportOptions extends BaseTransportOptions {
66
/** Custom headers for the transport. Used by the XHRTransport and FetchTransport */
@@ -13,13 +13,20 @@ export interface DenoTransportOptions extends BaseTransportOptions {
1313
export function makeFetchTransport(options: DenoTransportOptions): Transport {
1414
const url = new URL(options.url);
1515

16-
if (Deno.permissions.querySync({ name: 'net', host: url.host }).state !== 'granted') {
17-
consoleSandbox(() => {
18-
// eslint-disable-next-line no-console
19-
console.warn(`Sentry SDK requires 'net' permission to send events.
20-
Run with '--allow-net=${url.host}' to grant the requires permissions.`);
16+
Deno.permissions
17+
.query({ name: 'net', host: url.host })
18+
.then(({ state }) => {
19+
if (state !== 'granted') {
20+
consoleSandbox(() => {
21+
// eslint-disable-next-line no-console
22+
console.warn(`Sentry SDK requires 'net' permission to send events.
23+
Run with '--allow-net=${url.host}' to grant the requires permissions.`);
24+
});
25+
}
26+
})
27+
.catch(() => {
28+
logger.warn('Failed to read the "net" permission.');
2129
});
22-
}
2330

2431
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
2532
const requestOptions: RequestInit = {

0 commit comments

Comments
 (0)