bytebase/bytebase · error
CodeInternal
CodeInternal
Error message
failed to list roles
What it means
Thrown by ListRoles when the store query for workspace roles fails. The API wraps the store error in a CodeInternal connect error, so the caller sees a generic internal failure; the actual cause (SQL error, DB unreachable) is in the server logs.
Source
Thrown at backend/api/v1/role_service.go:43
store *store.Store
iamManager *iam.Manager
licenseService *enterprise.LicenseService
}
// NewRoleService returns a new instance of the role service.
func NewRoleService(store *store.Store, iamManager *iam.Manager, licenseService *enterprise.LicenseService) *RoleService {
return &RoleService{
store: store,
iamManager: iamManager,
licenseService: licenseService,
}
}
// ListRoles lists roles.
func (s *RoleService) ListRoles(ctx context.Context, _ *connect.Request[v1pb.ListRolesRequest]) (*connect.Response[v1pb.ListRolesResponse], error) {
roleMessages, err := s.store.ListRoles(ctx, &store.FindRoleMessage{Workspace: common.GetWorkspaceIDFromContext(ctx)})
if err != nil {
return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to list roles"))
}
return connect.NewResponse(&v1pb.ListRolesResponse{
Roles: convertToRoles(roleMessages),
}), nil
}
// GetRole gets a role.
func (s *RoleService) GetRole(ctx context.Context, req *connect.Request[v1pb.GetRoleRequest]) (*connect.Response[v1pb.Role], error) {
roleName := req.Msg.Name
roleID, err := common.GetRoleID(roleName)
if err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, err)
}
role, err := s.store.GetRole(ctx, &store.FindRoleMessage{Workspace: common.GetWorkspaceIDFromContext(ctx), ResourceID: &roleID})
if err != nil {
return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to get role"))
}
if role != nil {View on GitHub (pinned to 1870550677)
Solutions
- Check the metadata database connectivity and health (PG_URL, `psql -U bbdev bbdev`).
- Inspect server logs for the underlying store.ListRoles error.
- Verify the role table schema matches LATEST.sql / applied migrations.
- Retry after transient DB issues resolve.
Defensive patterns
Strategy: retry
Try / catch
catch (e) { if (e.code === CodeInternal) { await sleep(backoff); return retryListRoles(); } throw e; } Prevention
- Monitor metadata Postgres availability.
- Keep schema migrations applied and consistent with the server version.
- Add exponential-backoff retries for CodeInternal on read APIs.
When it happens
Trigger: Calling ListRoles while store.ListRoles's SELECT over the role table (filtered by the workspace ID from context) fails — metadata DB outage, bad SQL, or corrupted role rows that fail scanning.
Common situations: Metadata Postgres down or migrating; schema drift after a partial migration; connection pool exhaustion under heavy load; malformed workspace data in the context.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/9f9ec0543007a5f1.
Report an issue: GitHub.