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

Bug: Deno.permissions.querySync is not a function (Deno Deploy Runtime) #527

Open
carere opened this issue Oct 22, 2023 · 10 comments
Open
Labels
bug Something isn't working

Comments

@carere
Copy link

carere commented Oct 22, 2023

Everything is in the title, I'm deployed an API, and my database is EdgeDB, when I try to establish a connection with it, Edgedb try to read some env var. Thus, it call Deno.permissions.querySync, and I get the error highlighted in the title.
Here is my stack trace for more info.

TypeError: Deno.permissions.querySync is not a function
  at getEnv (https://deno.land/x/[email protected]/_src/adapter.shared.deno.ts:36:36)
  at parseConnectDsnAndArgs (https://deno.land/x/[email protected]/_src/conUtils.ts:538:36)
  at eventLoopTick (ext:core/01_core.js:183:11)
  at async ClientPool._parseConnectArguments (https://deno.land/x/[email protected]/_src/conUtils.ts:99:11)
  at async ClientPool.getNewConnection (https://deno.land/x/[email protected]/_src/baseClient.ts:375:20)
  at async ClientConnectionHolder._getConnection (https://deno.land/x/[email protected]/_src/baseClient.ts:62:26)
  at async ClientConnectionHolder.retryingFetch (https://deno.land/x/[email protected]/_src/baseClient.ts:175:20)
  at async Client.querySingle (https://deno.land/x/[email protected]/_src/baseClient.ts:615:14)
  at async Object.getKey (file:///src/shinzo/server/lucia/ashiso.adapter.ts:81:17)
  at async Auth.useKey (file:///node_modules/.deno/[email protected]/node_modules/lucia/dist/auth/index.js:192:29)

It's really annoying, since my API is totally unusable actually...
Is there a way to fix this ? Is this normal ? Should I do something on Deno Deploy ? If yes what ?

Best regards,

@nhrones
Copy link

nhrones commented Oct 22, 2023

I think env vars need to be set manually in Deploy.
https://docs.deno.com/deploy/manual/environment-variables

@dsherret dsherret transferred this issue from denoland/deno Oct 22, 2023
@carere
Copy link
Author

carere commented Oct 22, 2023

I did defined all my variables, the problem does not come from env var, is just the function querySync which is not available.
Is there a way to quickly patch this ??

@carere
Copy link
Author

carere commented Oct 22, 2023

For those encountering the same issue, here is my workaround while waiting this problem is solved on deno side:

// Horrible hack in order to fix `Deno.permissions.querySync` not being defined
if (!Deno.permissions.querySync) {
	(Deno.permissions as unknown as Record<string, unknown>)["querySync"] = (
		_pd: Deno.PermissionDescriptor,
	): { state: string } => ({ state: "granted" });
}
// End horrible hack

Put it at the first line of your entry-point ;)

@ry ry added the bug Something isn't working label Oct 27, 2023
@csvn
Copy link

csvn commented Dec 7, 2023

I had the same error while deploying when trying to use Sentry from deno.land

⠦ Finishing deployment...
⠧ Finishing deployment...
✖ Deployment failed.
error: The deployment failed: UNCAUGHT_EXCEPTION
TypeError: Deno.permissions.querySync is not a function
    at Object.makeFetchTransport [as transport] (https://deno.land/x/[email protected]/index.mjs:9785:24)
    at new BaseClient (https://deno.land/x/[email protected]/index.mjs:7425:33)
    at new ServerRuntimeClient (https://deno.land/x/[email protected]/index.mjs:8123:5)
    at new DenoClient (https://deno.land/x/[email protected]/index.mjs:8823:5)
    at initAndBind (https://deno.land/x/[email protected]/index.mjs:8367:18)
    at Module.init (https://deno.land/x/[email protected]/index.mjs:9908:3)
    at init (file:///src/src/core/tracing.ts:10:10)
    at file:///src/src/main.ts:12:1
    at eventLoopTick (ext:core/01_core.js:178:11)

@chillbrodev
Copy link

I had the same error while deploying when trying to use Sentry from deno.land

⠦ Finishing deployment...
⠧ Finishing deployment...
✖ Deployment failed.
error: The deployment failed: UNCAUGHT_EXCEPTION
TypeError: Deno.permissions.querySync is not a function
    at Object.makeFetchTransport [as transport] (https://deno.land/x/[email protected]/index.mjs:9785:24)
    at new BaseClient (https://deno.land/x/[email protected]/index.mjs:7425:33)
    at new ServerRuntimeClient (https://deno.land/x/[email protected]/index.mjs:8123:5)
    at new DenoClient (https://deno.land/x/[email protected]/index.mjs:8823:5)
    at initAndBind (https://deno.land/x/[email protected]/index.mjs:8367:18)
    at Module.init (https://deno.land/x/[email protected]/index.mjs:9908:3)
    at init (file:///src/src/core/tracing.ts:10:10)
    at file:///src/src/main.ts:12:1
    at eventLoopTick (ext:core/01_core.js:178:11)

I also encountered this with Sentry from Deno.land, I opened an issue on the Sentry-Deno . getsentry/sentry-javascript#10521

@3210jr
Copy link

3210jr commented Mar 6, 2024

@carere I am facing the same issue with edgedb. Your hack worked like a charm! Thanks a lot!

For those encountering the same issue, here is my workaround while waiting this problem is solved on deno side:

// Horrible hack in order to fix `Deno.permissions.querySync` not being defined
if (!Deno.permissions.querySync) {
	(Deno.permissions as unknown as Record<string, unknown>)["querySync"] = (
		_pd: Deno.PermissionDescriptor,
	): { state: string } => ({ state: "granted" });
}
// End horrible hack

Put it at the first line of your entry-point ;)

@KnorpelSenf
Copy link

I believe that Deno Deploy generally doesn't support sync APIs.

However, I remember that at some point, query was just implemented via a sync operation wrapped inside a call to Promise.resolve (at least in the CLI). Assuming that Deno Deploy is built similarly, it sounds reasonable to me that querySync should be supported on Deno Deploy. This won't be any more sync than the async API, and it will improve compatibility with some libraries.

outloudvi added a commit to MalitsPlus/IDOLY-Backend that referenced this issue Jun 23, 2024
@pawelgrzybek
Copy link

Do you know if there is any progress on trying to resolve this one Sentry/Deno side? Is there any way I could help to progress with this one?

I encountered the same bug which unfortunately makes Sentry not an option for me to use on Deno projects deployed to Deno Deploy.

@cirolosapio
Copy link

it was resolved on sentry side in this release
be sure to use 8.27+ version of the sentry sdk

@lionel-rowe
Copy link

For those encountering the same issue, here is my workaround while waiting this problem is solved on deno side:

// Horrible hack in order to fix `Deno.permissions.querySync` not being defined
if (!Deno.permissions.querySync) {
	(Deno.permissions as unknown as Record<string, unknown>)["querySync"] = (
		_pd: Deno.PermissionDescriptor,
	): { state: string } => ({ state: "granted" });
}
// End horrible hack

Put it at the first line of your entry-point ;)

This causes problems if the permission isn't available in Deploy though, as it will incorrectly return granted. Here's a version with the proper values for each permission's availability in Deploy (at time of writing):

const permissions = {
    run: 'denied',
    read: 'granted',
    write: 'denied',
    net: 'granted',
    env: 'granted',
    sys: 'denied',
    ffi: 'denied',
} as const

Deno.permissions.querySync ??= ({ name }) => {
    return {
        state: permissions[name],
        onchange: null,
        partial: false,
        addEventListener() {},
        removeEventListener() {},
        dispatchEvent() {
            return false
        },
    }
}

The permission statuses can be regenerated as follows in Deno Deploy playground:

Object.fromEntries(
    await Promise.all((['run', 'read', 'write', 'net', 'env', 'sys', 'ffi'] as const).map(async (name) => {
        try {
            return [name, (await Deno.permissions.query({ name })).state]
        } catch {
            return [name, 'denied']
        }
    })),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants