denoland / deploy_feedback

For reporting issues with Deno Deploy
https://deno.com/deploy
74 stars 5 forks source link

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

Open carere opened 8 months ago

carere commented 8 months ago

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/edgedb@v1.3.0/_src/adapter.shared.deno.ts:36:36)
  at parseConnectDsnAndArgs (https://deno.land/x/edgedb@v1.3.0/_src/conUtils.ts:538:36)
  at eventLoopTick (ext:core/01_core.js:183:11)
  at async ClientPool._parseConnectArguments (https://deno.land/x/edgedb@v1.3.0/_src/conUtils.ts:99:11)
  at async ClientPool.getNewConnection (https://deno.land/x/edgedb@v1.3.0/_src/baseClient.ts:375:20)
  at async ClientConnectionHolder._getConnection (https://deno.land/x/edgedb@v1.3.0/_src/baseClient.ts:62:26)
  at async ClientConnectionHolder.retryingFetch (https://deno.land/x/edgedb@v1.3.0/_src/baseClient.ts:175:20)
  at async Client.querySingle (https://deno.land/x/edgedb@v1.3.0/_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/lucia@2.7.1/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 commented 8 months ago

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

carere commented 8 months ago

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 commented 8 months ago

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 ;)

csvn commented 6 months ago

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/sentry@7.85.0/index.mjs:9785:24)
    at new BaseClient (https://deno.land/x/sentry@7.85.0/index.mjs:7425:33)
    at new ServerRuntimeClient (https://deno.land/x/sentry@7.85.0/index.mjs:8123:5)
    at new DenoClient (https://deno.land/x/sentry@7.85.0/index.mjs:8823:5)
    at initAndBind (https://deno.land/x/sentry@7.85.0/index.mjs:8367:18)
    at Module.init (https://deno.land/x/sentry@7.85.0/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 commented 5 months ago

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/sentry@7.85.0/index.mjs:9785:24)
    at new BaseClient (https://deno.land/x/sentry@7.85.0/index.mjs:7425:33)
    at new ServerRuntimeClient (https://deno.land/x/sentry@7.85.0/index.mjs:8123:5)
    at new DenoClient (https://deno.land/x/sentry@7.85.0/index.mjs:8823:5)
    at initAndBind (https://deno.land/x/sentry@7.85.0/index.mjs:8367:18)
    at Module.init (https://deno.land/x/sentry@7.85.0/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 . https://github.com/getsentry/sentry-javascript/issues/10521

3210jr commented 3 months ago

@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 commented 3 months ago

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.