{"record":{"id":"642c745a624f6d1d","repo":"JuliusBrussee/caveman","slug":"postgres-set-organization-scope-w","errorCode":null,"errorMessage":"postgres: set organization scope: %w","messagePattern":"postgres: set organization scope: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/postgresconfig/postgresconfig.go","lineNumber":775,"sourceCode":"\t}\n\treturn nil\n}\n\n// WithOrg runs fn inside a transaction whose tenant GUC is transaction-local.\n// Empty scopes are rejected: tenant work must never degrade to an unscoped\n// query when RLS is the hard boundary.\nfunc WithOrg(ctx context.Context, pool *pgxpool.Pool, orgID string, fn func(pgx.Tx) error) error {\n\torgID = strings.TrimSpace(orgID)\n\tif orgID == \"\" {\n\t\treturn errors.New(\"postgres: organization scope is required\")\n\t}\n\ttx, err := pool.Begin(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer func() { _ = tx.Rollback(ctx) }()\n\tif _, err := tx.Exec(ctx, `SELECT set_config('app.current_organization_id', $1, true)`, orgID); err != nil {\n\t\treturn fmt.Errorf(\"postgres: set organization scope: %w\", err)\n\t}\n\tif err := fn(tx); err != nil {\n\t\treturn err\n\t}\n\treturn tx.Commit(ctx)\n}\n","sourceCodeStart":757,"sourceCodeEnd":782,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/postgresconfig/postgresconfig.go#L757-L782","documentation":"Error \"postgres: set organization scope: %w\" thrown in JuliusBrussee/caveman.","triggerScenarios":"Thrown at shared/platform/postgresconfig/postgresconfig.go:775 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix setting the organization scope on the connection."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}