P
Prisma5mo ago
qoouep

Debugging Invalid `prisma.$queryRaw()` invocation

I am getting an Invalid prisma.$queryRaw() invocation error when running my code in the cloud (specifically trigger.dev). I have a fairly distinct setup in that I have multiple packages abstracting different Prisma schemas in my monorepo. They are all getting bundled together for Trigger with some bespoke code to copy the binary combined with the prisma extension. Example snippet from the schemas, which are all configured roughly the same way.
datasource db {
provider = "postgresql"
url = env("DB_URL")
directUrl = env("DIRECT_DB_URL")
relationMode = "foreignKeys"
extensions = [vector]
}

generator client {
provider = "prisma-client"
previewFeatures = ["relationJoins", "postgresqlExtensions", "typedSql", "queryCompiler", "driverAdapters"]
output = "../__generated__/prisma"
engineType = "library"
}
datasource db {
provider = "postgresql"
url = env("DB_URL")
directUrl = env("DIRECT_DB_URL")
relationMode = "foreignKeys"
extensions = [vector]
}

generator client {
provider = "prisma-client"
previewFeatures = ["relationJoins", "postgresqlExtensions", "typedSql", "queryCompiler", "driverAdapters"]
output = "../__generated__/prisma"
engineType = "library"
}
How can I get more information about why the query is failing? I can't really trace any more information about the error, except that I see an ECONNREFUSED in the error in the Trigger console. My query works fine on my laptop, but is broken in Trigger, so it could be the specific setup I have in place breaks specifically queryRaw, but works for ORM queries. How could I get more information on what is going wrong with this?
Trigger.dev
Welcome to the Trigger.dev docs - Trigger.dev
Find all the resources and guides you need to get started
4 Replies
Prisma AI Help
Prisma AI Help5mo ago
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
Nurul
Nurul5mo ago
Can you share the full error message you are getting? Can you set DEBUG env variable and see if you get more information? https://www.prisma.io/docs/orm/prisma-client/debugging-and-troubleshooting/debugging
Debugging (Reference) | Prisma Documentation
This page explains how to enable debugging output for Prisma Client by setting the DEBUG environment variable.
qoouep
qoouepOP5mo ago
That's most of the useful information in the error. This is the error object with the app portion of the stack trace removed:
{
"name": "PrismaClientKnownRequestError",
"stack": "PrismaClientKnownRequestError: \nInvalid `prisma.$queryRaw()` invocation:\n\n\n\n at Qn.handleRequestError (file:///app/node_modules/@prisma/client/runtime/library.mjs:128:7460)\n at Qn.handleAndLogRequestError (file:///app/node_modules/@prisma/client/runtime/library.mjs:128:6785)\n at Qn.request (file:///app/node_modules/@prisma/client/runtime/library.mjs:128:6492)\n at l (file:///app/node_modules/@prisma/client/runtime/library.mjs:137:9767)\n",
"message": "\nInvalid `prisma.$queryRaw()` invocation:\n\n\n"
}
{
"name": "PrismaClientKnownRequestError",
"stack": "PrismaClientKnownRequestError: \nInvalid `prisma.$queryRaw()` invocation:\n\n\n\n at Qn.handleRequestError (file:///app/node_modules/@prisma/client/runtime/library.mjs:128:7460)\n at Qn.handleAndLogRequestError (file:///app/node_modules/@prisma/client/runtime/library.mjs:128:6785)\n at Qn.request (file:///app/node_modules/@prisma/client/runtime/library.mjs:128:6492)\n at l (file:///app/node_modules/@prisma/client/runtime/library.mjs:137:9767)\n",
"message": "\nInvalid `prisma.$queryRaw()` invocation:\n\n\n"
}
I am wondering if libquery_engine-debian-openssl-3.0.x.so.node does not handle my embeddings the same way as the libquery_engine-darwin-arm64.dylib.node which runs locally I am including something like this in my query:
const getSql = (embedding: Array<number>) => Prisma.sql`
select
id,
"embedding" <=> ${JSON.stringify(embedding)}::halfvec as distance
from "Object"
`;
const getSql = (embedding: Array<number>) => Prisma.sql`
select
id,
"embedding" <=> ${JSON.stringify(embedding)}::halfvec as distance
from "Object"
`;
Actually, I figured it out. It turns out that in my cloud environment, I was providing the wrong environment variable for the database URL because I have an abstraction locally which renames them. It's kind of surprising that the driver doesn't have a clearer error when the database URL is missing entirely—Prisma could definitely have better error messaging
Nurul
Nurul5mo ago
I am glad to hear that you were able to figure it out! Thanks for the feedback about nicer error message 🙏

Did you find this page helpful?