{"record":{"id":"5c9ae77f8e8e6e67","repo":"Dokploy/dokploy","slug":"bad-request-5c9ae7","errorCode":"BAD_REQUEST","errorMessage":"Error input: Inserting destination","messagePattern":"Error input: Inserting destination","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"packages/server/src/services/destination.ts","lineNumber":26,"sourceCode":"import type { z } from \"zod\";\n\nexport type Destination = typeof destinations.$inferSelect;\n\nexport const createDestination = async (\n\tinput: z.infer<typeof apiCreateDestination>,\n\torganizationId: string,\n) => {\n\tconst newDestination = await db\n\t\t.insert(destinations)\n\t\t.values({\n\t\t\t...input,\n\t\t\torganizationId: organizationId,\n\t\t})\n\t\t.returning()\n\t\t.then((value) => value[0]);\n\n\tif (!newDestination) {\n\t\tthrow new TRPCError({\n\t\t\tcode: \"BAD_REQUEST\",\n\t\t\tmessage: \"Error input: Inserting destination\",\n\t\t});\n\t}\n\n\treturn newDestination;\n};\n\nexport const findDestinationById = async (destinationId: string) => {\n\tconst destination = await db.query.destinations.findFirst({\n\t\twhere: and(eq(destinations.destinationId, destinationId)),\n\t});\n\tif (!destination) {\n\t\tthrow new TRPCError({\n\t\t\tcode: \"NOT_FOUND\",\n\t\t\tmessage: \"Destination not found\",\n\t\t});\n\t}","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/packages/server/src/services/destination.ts#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"Submitting a destination form with empty/invalid values; organizationId not resolved from auth context; DB schema out of sync; unique constraint on destination name.","solutions":["Validate all required destination fields (name, provider type, credentials) before submitting","Confirm the user's organization context is active and organizationId is correct","Check DB logs for the constraint error; enable SQL logging","Apply migrations to sync schema"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!input.name || !input.provider || !organizationId) throw new Error(\"Missing destination fields\");","typeGuard":"const isCreateDestinationInput = (x: unknown): x is CreateDestinationInput =>\n  typeof (x as any)?.name === \"string\" && typeof (x as any)?.provider === \"string\";","tryCatchPattern":"try { await createDestination(input); } catch (e) { if (e instanceof TRPCError && e.code === \"BAD_REQUEST\") { /* re-validate fields */ } }","preventionTips":["Validate destination form fields client-side","Ensure org context resolves before insert","Check DB constraints via logs when inserts fail"],"tags":["database","destination","backup"],"backgroundTag":"database-insert-returning-empty","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}