{"record":{"id":"7744b8ef66dde912","repo":"Dokploy/dokploy","slug":"bad-request-7744b8","errorCode":"BAD_REQUEST","errorMessage":"Error creating this Bitbucket provider","messagePattern":"Error creating this Bitbucket provider","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"apps/dokploy/server/api/routers/bitbucket.ts","lineNumber":46,"sourceCode":"\tcreate: withPermission(\"gitProviders\", \"create\")\n\t\t.input(apiCreateBitbucket)\n\t\t.mutation(async ({ input, ctx }) => {\n\t\t\ttry {\n\t\t\t\tconst result = await createBitbucket(\n\t\t\t\t\tinput,\n\t\t\t\t\tctx.session.activeOrganizationId,\n\t\t\t\t\tctx.session.userId,\n\t\t\t\t);\n\n\t\t\t\tawait audit(ctx, {\n\t\t\t\t\taction: \"create\",\n\t\t\t\t\tresourceType: \"gitProvider\",\n\t\t\t\t\tresourceName: input.name,\n\t\t\t\t});\n\n\t\t\t\treturn result;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\t\tmessage: \"Error creating this Bitbucket provider\",\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t}),\n\tone: protectedProcedure\n\t\t.input(apiFindOneBitbucket)\n\t\t.query(async ({ input, ctx }) => {\n\t\t\tconst bitbucket = await findBitbucketById(input.bitbucketId);\n\t\t\tawait assertGitProviderAccess(ctx.session, bitbucket.gitProvider);\n\t\t\treturn bitbucket;\n\t\t}),\n\tbitbucketProviders: protectedProcedure.query(async ({ ctx }) => {\n\t\tconst accessibleIds = await getAccessibleGitProviderIds(ctx.session);\n\n\t\tlet result = await db.query.bitbucket.findMany({\n\t\t\twith: {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/bitbucket.ts#L28-L64","documentation":"This TRPCError (BAD_REQUEST) is a catch-all wrapper thrown when the underlying createBitbucketProvider service call fails while creating a Bitbucket git provider in Dokploy. The original error is attached via `cause`, so the real reason (bad credentials, duplicate name, DB constraint) is nested inside. It is not a Bitbucket API error per se — any failure inside the try block is masked by this generic message.","triggerScenarios":"Calling the `bitbucket.create` mutation with malformed credentials (wrong workspace/repo-slug format), a duplicate provider name, an invalid bitbucketUsername, or when the database insert fails. Inspect `error.cause` for the actual driver error.","commonSituations":"OAuth app credentials misconfigured, pasting a workspace UUID instead of the slug, creating a second provider with the same name, or a transient DB outage during creation.","solutions":["Inspect the TRPC error's `cause` on the client/server log to find the real underlying message","Verify the Bitbucket provider input: name uniqueness, workspace slug, username and credentials format","Retry after fixing credentials; confirm the DB is reachable and the `git_provider` table has no constraint violations","If the cause is a Bitbucket API 401/403, reissue the app password/OAuth client and try again"],"exampleFix":"// before\nawait trpc.bitbucket.create.mutate({ name: 'my-repo', ... });\n// Error: Error creating this Bitbucket provider\n\n// after — surface the underlying cause\ntry {\n  await trpc.bitbucket.create.mutate({ name: 'my-repo', ... });\n} catch (e) {\n  const cause = e?.cause ?? e;\n  console.error('bitbucket.create failed:', cause?.message ?? cause);\n  throw cause;\n}","handlingStrategy":"try-catch","validationCode":"// Validate input shape before calling\nif (!input?.name || !input?.bitbucketUsername || !input?.workspace) {\n  throw new Error('Missing required Bitbucket provider fields');\n}","typeGuard":"function isValidBitbucketInput(i: unknown): i is { name: string; workspace: string; bitbucketUsername: string } {\n  return typeof i === 'object' && i !== null\n    && typeof (i as any).name === 'string' && (i as any).name.length > 0\n    && typeof (i as any).workspace === 'string'\n    && typeof (i as any).bitbucketUsername === 'string';\n}","tryCatchPattern":"try {\n  await trpc.bitbucket.create.mutate(input);\n} catch (e: any) {\n  const cause = e?.cause ?? e;\n  if (/duplicate key|unique/i.test(cause?.message ?? '')) throw new Error('Provider name already exists');\n  if (/401|credentials/i.test(cause?.message ?? '')) throw new Error('Invalid Bitbucket credentials');\n  throw cause;\n}","preventionTips":["Always name providers uniquely per organization","Test credentials with bitbucket.testConnection before automating","Log the TRPC cause, not just the top-level message"],"tags":["dokploy","trpc","bitbucket","git-provider","catch-all"],"backgroundTag":"trpc-bad-request-wrapped-error","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}