{"record":{"id":"3f00635cdae030b0","repo":"eyaltoledano/claude-task-master","slug":"api-error","errorCode":"API_ERROR","errorMessage":"`Failed to fetch organizations: ${error.message}`","messagePattern":"`Failed to fetch organizations: (.+?)`","errorType":"exception","errorClass":"TaskMasterError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/auth/services/organization.service.ts","lineNumber":69,"sourceCode":"\tconstructor(private supabaseClient: SupabaseClient<Database>) {}\n\n\t/**\n\t * Get all organizations for the authenticated user\n\t */\n\tasync getOrganizations(): Promise<Organization[]> {\n\t\ttry {\n\t\t\t// The user is already authenticated via the Authorization header\n\t\t\t// Query the user_accounts view/table (filtered by RLS for current user)\n\t\t\tconst { data, error } = await this.supabaseClient\n\t\t\t\t.from('user_accounts')\n\t\t\t\t.select(`\n\t\t\t\t\tid,\n\t\t\t\t\tname,\n\t\t\t\t\tslug\n\t\t\t\t`);\n\n\t\t\tif (error) {\n\t\t\t\tthrow new TaskMasterError(\n\t\t\t\t\t`Failed to fetch organizations: ${error.message}`,\n\t\t\t\t\tERROR_CODES.API_ERROR,\n\t\t\t\t\t{ operation: 'getOrganizations' },\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!data || data.length === 0) {\n\t\t\t\tthis.logger.debug('No organizations found for user');\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\t// Map to our Organization interface\n\t\t\treturn data.map((org) => ({\n\t\t\t\tid: org.id ?? '',\n\t\t\t\tname: org.name ?? '',\n\t\t\t\tslug: org.slug ?? org.id ?? '' // Use ID as fallback if slug is null\n\t\t\t}));","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/auth/services/organization.service.ts#L51-L87","documentation":"Thrown by OrganizationService.getOrganizations when the Supabase query against the user_accounts view returns an error object. The raw Supabase/Postgres error message is embedded in the thrown TaskMasterError, with code API_ERROR and context {operation:'getOrganizations'}. It signals a database/API-level failure (schema, RLS, or network), not an empty result set.","triggerScenarios":"Calling getOrganizations() when the user_accounts table/view does not exist or was renamed, RLS denies access to the current user, the JWT/session is expired or invalid, or the Supabase request fails (network error, 5xx).","commonSituations":"Expired auth token after idle time; server schema migration renamed user_accounts; user's membership rows deleted so RLS rejects; offline or corporate proxy blocking the Supabase host.","solutions":["Read error.cause (the embedded Supabase error) for the exact Postgres/RLS message","Re-authenticate to refresh an expired JWT, then retry","Check the user_accounts view exists in the current schema (migrations may have renamed it)","Verify network connectivity / Supabase project status","If RLS-related, confirm the user has an active user_accounts row (account membership)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight session check before querying organizations\nconst { data: sessionData, error: sessionErr } = await supabase.auth.getSession();\nif (sessionErr || !sessionData.session) {\n  throw new Error('Not authenticated: run `tm auth login` before fetching organizations');\n}","typeGuard":"function isTaskMasterApiError(e: unknown): e is TaskMasterError {\n  return e instanceof TaskMasterError && e.code === ERROR_CODES.API_ERROR;\n}","tryCatchPattern":"try {\n  const orgs = await orgService.getOrganizations();\n} catch (e) {\n  if (isTaskMasterApiError(e)) {\n    const cause = e.cause as { code?: string; message?: string };\n    if (cause?.code === '42P01') console.error('user_accounts view missing — schema out of date');\n    else if (cause?.code === '42501') console.error('RLS denied access — check account membership');\n    else console.error('Fetch organizations failed:', cause?.message ?? e.message);\n  } else throw e;\n}","preventionTips":["Refresh the auth session before long-running operations","Validate the user has at least one account membership before querying","Run schema migrations in sync with the client's expected view/table names","Check network reachability of the Supabase host before batch operations","Inspect error.cause (the raw Supabase error) rather than only the top-level message"],"tags":["supabase","database","rls","api"],"backgroundTag":"supabase-query-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}