Dokploy/dokploy · error · TRPCError

BAD_REQUEST

BAD_REQUEST

Error message

Error input: Inserting destination

What it means

Thrown by createDestination when the insert of a new destination row returns no row (newDestination falsy). It is a defensive guard meaning the destination (backup/upload target) could not be inserted into the database.

Source

Thrown at packages/server/src/services/destination.ts:26

import type { z } from "zod";

export type Destination = typeof destinations.$inferSelect;

export const createDestination = async (
	input: z.infer<typeof apiCreateDestination>,
	organizationId: string,
) => {
	const newDestination = await db
		.insert(destinations)
		.values({
			...input,
			organizationId: organizationId,
		})
		.returning()
		.then((value) => value[0]);

	if (!newDestination) {
		throw new TRPCError({
			code: "BAD_REQUEST",
			message: "Error input: Inserting destination",
		});
	}

	return newDestination;
};

export const findDestinationById = async (destinationId: string) => {
	const destination = await db.query.destinations.findFirst({
		where: and(eq(destinations.destinationId, destinationId)),
	});
	if (!destination) {
		throw new TRPCError({
			code: "NOT_FOUND",
			message: "Destination not found",
		});
	}

View on GitHub (pinned to 546686ea35)

Solutions

  1. Validate all required destination fields (name, provider type, credentials) before submitting
  2. Confirm the user's organization context is active and organizationId is correct
  3. Check DB logs for the constraint error; enable SQL logging
  4. Apply migrations to sync schema
Defensive patterns

Strategy: validation

Validate before calling

if (!input.name || !input.provider || !organizationId) throw new Error("Missing destination fields");

Type guard

const isCreateDestinationInput = (x: unknown): x is CreateDestinationInput =>
  typeof (x as any)?.name === "string" && typeof (x as any)?.provider === "string";

Try / catch

try { await createDestination(input); } catch (e) { if (e instanceof TRPCError && e.code === "BAD_REQUEST") { /* re-validate fields */ } }

Prevention

When it happens

Trigger: Calling the create-destination API/mutation where the insert fails: missing required fields (name, provider, organizationId), constraint violations, or schema mismatch — resulting in .returning() resolving to undefined.

Common situations: Submitting a destination form with empty/invalid values; organizationId not resolved from auth context; DB schema out of sync; unique constraint on destination name.

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/5c9ae77f8e8e6e67. Report an issue: GitHub.