Dokploy/dokploy · error · TRPCError
BAD_REQUEST
BAD_REQUEST
Error message
Error creating the Git provider
What it means
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.
Source
Thrown at packages/server/src/services/gitlab.ts:31
export const createGitlab = async (
input: z.infer<typeof apiCreateGitlab>,
organizationId: string,
userId: string,
) => {
return await db.transaction(async (tx) => {
const newGitProvider = await tx
.insert(gitProvider)
.values({
providerType: "gitlab",
organizationId: organizationId,
name: input.name,
userId: userId,
})
.returning()
.then((response) => response[0]);
if (!newGitProvider) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error creating the Git provider",
});
}
await tx
.insert(gitlab)
.values({
...input,
gitProviderId: newGitProvider?.gitProviderId,
})
.returning()
.then((response) => response[0]);
});
};
export const findGitlabById = async (gitlabId: string) => {
const gitlabProviderResult = await db.query.gitlab.findFirst({View on GitHub (pinned to 546686ea35)
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
Example fix
// before
const newGitProvider = await tx.insert(gitProvider).values({...}).returning().then(r => r[0]);
if (!newGitProvider) {
throw new TRPCError({ code: 'BAD_REQUEST', message: 'Error creating the Git provider' });
}
// after: surface the underlying cause for diagnosis
if (!newGitProvider) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Error creating the Git provider',
cause: 'Insert returned no row; check unique constraints on token/provider',
});
} Defensive patterns
Strategy: validation
Validate before calling
const existing = await db.select().from(gitProvider).where(eq(gitProvider.gitToken, token));
if (existing.length > 0) throw new Error('Provider with this token already registered'); Try / catch
try { await trpc.gitlab.createGitlab.mutate(input); } catch (e) { if (e instanceof TRPCClientError && e.data?.code === 'BAD_REQUEST') { /* inspect server cause, likely DB-side */ } } Prevention
- Validate provider tokens/credentials before calling create
- Register each Git provider once; track registered tokens client-side
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: BAD_REQUEST error code: request rejected as invalid (HTTP 400) - causes and fixes across libraries — this error's family across 8 libraries.
Related errors
AI-assisted analysis of Dokploy/dokploy@546686ea35 (2026-08-27).
Data as JSON: /api/errors/78027e75d643db68.
Report an issue: GitHub.