Skip to content
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

fix(deno): Don't rely on Deno.permissions.querySync #13378

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
5 changes: 5 additions & 0 deletions packages/deno/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { SDK_VERSION, ServerRuntimeClient } from '@sentry/core';
import type { DenoClientOptions } from './types';

function getHostName(): string | undefined {
// Deno.permissions.querySync is not available on Deno Deploy
if (!Deno.permissions.querySync) {
return undefined;
}

const result = Deno.permissions.querySync({ name: 'sys', kind: 'hostname' });
return result.state === 'granted' ? Deno.hostname() : undefined;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/deno/src/integrations/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function getOSName(): string {
}
}

function getOSRelease(): string | undefined {
return Deno.permissions.querySync({ name: 'sys', kind: 'osRelease' }).state === 'granted'
async function getOSRelease(): Promise<string | undefined> {
return (await Deno.permissions.query({ name: 'sys', kind: 'osRelease' })).state === 'granted'
? Deno.osRelease()
: undefined;
}
Expand All @@ -35,7 +35,7 @@ async function addDenoRuntimeContext(event: Event): Promise<Event> {
},
os: {
name: getOSName(),
version: getOSRelease(),
version: await getOSRelease(),
},
v8: {
name: 'v8',
Expand Down
5 changes: 5 additions & 0 deletions packages/deno/src/integrations/normalizepaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function appRootFromErrorStack(error: Error): string | undefined {
}

function getCwd(): string | undefined {
// Deno.permissions.querySync is not available on Deno Deploy
if (!Deno.permissions.querySync) {
return undefined;
}

// We don't want to prompt for permissions so we only get the cwd if
// permissions are already granted
const permission = Deno.permissions.querySync({ name: 'read', path: './' });
Expand Down
21 changes: 14 additions & 7 deletions packages/deno/src/transports/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTransport } from '@sentry/core';
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';
import { consoleSandbox, rejectedSyncPromise } from '@sentry/utils';
import { consoleSandbox, logger, rejectedSyncPromise } from '@sentry/utils';

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

if (Deno.permissions.querySync({ name: 'net', host: url.host }).state !== 'granted') {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(`Sentry SDK requires 'net' permission to send events.
Run with '--allow-net=${url.host}' to grant the requires permissions.`);
Deno.permissions
.query({ name: 'net', host: url.host })
.then(({ state }) => {
if (state !== 'granted') {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(`Sentry SDK requires 'net' permission to send events.
Run with '--allow-net=${url.host}' to grant the requires permissions.`);
});
}
})
.catch(() => {
logger.warn('Failed to read the "net" permission.');
});
}

function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
const requestOptions: RequestInit = {
Expand Down
Loading