{"record":{"id":"78027e75d643db68","repo":"Dokploy/dokploy","slug":"bad-request-78027e","errorCode":"BAD_REQUEST","errorMessage":"Error creating the Git provider","messagePattern":"Error creating the Git provider","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"packages/server/src/services/gitlab.ts","lineNumber":31,"sourceCode":"export const createGitlab = async (\n\tinput: z.infer<typeof apiCreateGitlab>,\n\torganizationId: string,\n\tuserId: string,\n) => {\n\treturn await db.transaction(async (tx) => {\n\t\tconst newGitProvider = await tx\n\t\t\t.insert(gitProvider)\n\t\t\t.values({\n\t\t\t\tproviderType: \"gitlab\",\n\t\t\t\torganizationId: organizationId,\n\t\t\t\tname: input.name,\n\t\t\t\tuserId: userId,\n\t\t\t})\n\t\t\t.returning()\n\t\t\t.then((response) => response[0]);\n\n\t\tif (!newGitProvider) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\tmessage: \"Error creating the Git provider\",\n\t\t\t});\n\t\t}\n\n\t\tawait tx\n\t\t\t.insert(gitlab)\n\t\t\t.values({\n\t\t\t\t...input,\n\t\t\t\tgitProviderId: newGitProvider?.gitProviderId,\n\t\t\t})\n\t\t\t.returning()\n\t\t\t.then((response) => response[0]);\n\t});\n};\n\nexport const findGitlabById = async (gitlabId: string) => {\n\tconst gitlabProviderResult = await db.query.gitlab.findFirst({","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/packages/server/src/services/gitlab.ts#L13-L49","documentation":"Thrown by createGitlab when a Drizzle ORM insert into the git provider table with .returning() yields no row. Although it maps to BAD_REQUEST, it actually signals that the database insert failed or returned an empty result set, typically a DB-side problem rather than a client input problem.","triggerScenarios":"Calling the createGitlab mutation (POST /trpc/gitlab.createGitlab) when the underlying transaction's INSERT ... RETURNING returns zero rows — e.g. a failed DB constraint (unique provider token), a cancelled transaction, or a database connectivity issue inside the tx block.","commonSituations":"Registering the same GitLab access token twice against a unique constraint, a database schema drift between the Drizzle schema and the actual Postgres tables, or the DB dropping the connection mid-transaction.","solutions":["Check server logs for the underlying Postgres/Drizzle error just before this TRPCError is thrown","Verify uniqueness constraints on the git provider table (token, provider name) and retry with a fresh token","Run drizzle migrations to confirm the schema matches (e.g. pnpm db:push or the project's migrate script)","If it persists, inspect db connection pool settings and database availability"],"exampleFix":"// before\nconst newGitProvider = await tx.insert(gitProvider).values({...}).returning().then(r => r[0]);\nif (!newGitProvider) {\n  throw new TRPCError({ code: 'BAD_REQUEST', message: 'Error creating the Git provider' });\n}\n\n// after: surface the underlying cause for diagnosis\nif (!newGitProvider) {\n  throw new TRPCError({\n    code: 'BAD_REQUEST',\n    message: 'Error creating the Git provider',\n    cause: 'Insert returned no row; check unique constraints on token/provider',\n  });\n}","handlingStrategy":"validation","validationCode":"const existing = await db.select().from(gitProvider).where(eq(gitProvider.gitToken, token));\nif (existing.length > 0) throw new Error('Provider with this token already registered');","typeGuard":null,"tryCatchPattern":"try { await trpc.gitlab.createGitlab.mutate(input); } catch (e) { if (e instanceof TRPCClientError && e.data?.code === 'BAD_REQUEST') { /* inspect server cause, likely DB-side */ } }","preventionTips":["Validate provider tokens/credentials before calling create","Register each Git provider once; track registered tokens client-side"],"tags":["database","drizzle-orm","git-provider","insert"],"backgroundTag":"database-insert-returned-no-row","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}