Dokploy/dokploy · error · TRPCError

BAD_REQUEST

BAD_REQUEST

Error message

Error creating the project

What it means

createProject inserts a new project row via Drizzle's .returning() and expects the first returned row. If the insert returns no row (or undefined), it throws a tRPC BAD_REQUEST error indicating the database insert failed to produce a project record. This is a defensive guard after the insert rather than a user-input validation.

Source

Thrown at packages/server/src/services/project.ts:34

import { createProductionEnvironment } from "./environment";

export type Project = typeof projects.$inferSelect;

export const createProject = async (
	input: z.infer<typeof apiCreateProject>,
	organizationId: string,
) => {
	const newProject = await db
		.insert(projects)
		.values({
			...input,
			organizationId: organizationId,
		})
		.returning()
		.then((value) => value[0]);

	if (!newProject) {
		throw new TRPCError({
			code: "BAD_REQUEST",
			message: "Error creating the project",
		});
	}

	// Automatically create a production environment
	const newEnvironment = await createProductionEnvironment(
		newProject.projectId,
	);
	return {
		project: newProject,
		environment: newEnvironment,
	};
};

export const serviceColumns = {
	name: true,
	description: true,

View on GitHub (pinned to 546686ea35)

Solutions

  1. Check the database logs for why the insert produced no returned row (triggers, constraints, schema drift)
  2. Verify the Drizzle schema matches the actual database (run migrations / drizzle-kit push) and that .returning() is supported for your DB engine
  3. Retry the createProject call; if persistent, inspect the insert payload (organizationId, name) for constraint violations surfaced elsewhere
Defensive patterns

Strategy: try-catch

Try / catch

try { await createProject(input) } catch (e) { if (e instanceof TRPCError && e.code === 'BAD_REQUEST' && e.message === 'Error creating the project') { /* surface as system error, retry once */ } }

Prevention

When it happens

Trigger: POST to the createProject tRPC mutation where the underlying db.insert(...).returning() yields an empty result — e.g. a database trigger swallowing the insert, a failed constraint with silent handling, or a driver/ORM mismatch returning no rows.

Common situations: Rare DB edge cases: BEFORE INSERT triggers returning NULL, replication/rollback weirdness, Drizzle version changes altering .returning() behavior on the target database, or the insert silently failing due to schema drift between the Drizzle schema and the actual database tables.

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/76e0dc775c36a291. Report an issue: GitHub.