Dokploy/dokploy · error · TRPCError
INTERNAL_SERVER_ERROR
INTERNAL_SERVER_ERROR
Error message
Failed to create organization
What it means
Defensive check after inserting a new organization row with Drizzle (.returning().then(res => res[0])): if the insert returned no row, the mutation throws INTERNAL_SERVER_ERROR. This only happens if the INSERT silently returns empty — rare, but can occur with broken BEFORE INSERT triggers, schema drift, or a DB driver/serialization hiccup.
Source
Thrown at apps/dokploy/server/api/routers/organization.ts:56
}
if (IS_CLOUD) {
await assertOrganizationLimit(ctx.user.id);
}
const result = await db
.insert(organization)
.values({
...input,
slug: nanoid(),
createdAt: new Date(),
ownerId: ctx.user.id,
})
.returning()
.then((res) => res[0]);
if (!result) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Failed to create organization",
});
}
// Check if this is the user's first organization
const existingMemberships = await db.query.member.findMany({
where: eq(member.userId, ctx.user.id),
});
await db.insert(member).values({
organizationId: result.id,
role: "owner",
createdAt: new Date(),
userId: ctx.user.id,
});
await audit(ctx, {
action: "create",View on GitHub (pinned to 546686ea35)
Solutions
- Retry the create — transient driver issues resolve themselves
- Inspect the organizations table for triggers/rules: SELECT event_manipulation, action_statement FROM information_schema.triggers WHERE event_object_table='organization'
- Verify schema is up to date (run migrations / dokploy upgrade)
- Check Postgres logs for errors at the moment of the insert
Example fix
// before
await trpc.organization.create.mutate({ name }); // INTERNAL_SERVER_ERROR: Failed to create organization
// after: drop the rogue trigger, then retry
-- DROP TRIGGER skip_insert ON organization;
await trpc.organization.create.mutate({ name }); Defensive patterns
Strategy: retry
Validate before calling
const healthy = await db.execute(sql`select 1`);
if (!healthy) throw new Error('DB not ready'); Type guard
null
Try / catch
try { await create(input); } catch (e) { if (getTRPCCode(e) === 'INTERNAL_SERVER_ERROR') await backoffRetry(create, input, 2); else throw e; } Prevention
- Don't add custom triggers/rules to Dokploy's tables
- Retry once — empty .returning() is usually transient
- Keep schema migrations in sync
When it happens
Trigger: The organization INSERT executes but `.returning()` yields zero rows — e.g. a trigger swallowing the insert, mismatched schema after failed migration, or unusual Postgres behavior (RULE rewriting the statement).
Common situations: Database restored from a dump with custom triggers/rules; partial upgrade left the returning-capable schema inconsistent; transient connection pool failure mid-statement.
Related errors
- Failed to fetch models: ${errorText}
- BAD_REQUEST
- INTERNAL_SERVER_ERROR
- FORBIDDEN
- No response received from the model
AI-assisted analysis of Dokploy/dokploy@546686ea35 (2026-08-27).
Data as JSON: /api/errors/0e14fc4e008e32e9.
Report an issue: GitHub.