{"record":{"id":"a14fae0b92ab8f9a","repo":"SigNoz/signoz","slug":"codeinternal-a14fae","errorCode":"CodeInternal","errorMessage":"unable to fetch routing policy with ID: %s","messagePattern":"unable to fetch routing policy with ID: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":500,"severity":"error","filePath":"pkg/alertmanager/nfmanager/nfroutingstore/sqlroutingstore/store.go","lineNumber":29,"sourceCode":"\ntype store struct {\n\tsqlstore sqlstore.SQLStore\n}\n\nfunc NewStore(sqlstore sqlstore.SQLStore) routeTypes.RouteStore {\n\treturn &store{\n\t\tsqlstore: sqlstore,\n\t}\n}\n\nfunc (store *store) GetByID(ctx context.Context, orgId string, id string) (*routeTypes.RoutePolicy, error) {\n\troute := new(routeTypes.RoutePolicy)\n\terr := store.sqlstore.BunDBCtx(ctx).NewSelect().Model(route).Where(\"id = ?\", id).Where(\"org_id = ?\", orgId).Scan(ctx)\n\tif err != nil {\n\t\tif errors.Is(err, sql.ErrNoRows) {\n\t\t\treturn nil, store.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, \"routing policy with ID: %s does not exist\", id)\n\t\t}\n\t\treturn nil, errors.Wrapf(err, errors.TypeInternal, errors.CodeInternal, \"unable to fetch routing policy with ID: %s\", id)\n\t}\n\n\treturn route, nil\n}\n\nfunc (store *store) Create(ctx context.Context, route *routeTypes.RoutePolicy) error {\n\t_, err := store.sqlstore.BunDBCtx(ctx).NewInsert().Model(route).Exec(ctx)\n\tif err != nil {\n\t\treturn errors.NewInternalf(errors.CodeInternal, \"error creating routing policy with ID: %s\", route.ID)\n\t}\n\n\treturn nil\n}\n\nfunc (store *store) CreateBatch(ctx context.Context, route []*routeTypes.RoutePolicy) error {\n\t_, err := store.sqlstore.BunDBCtx(ctx).NewInsert().Model(&route).Exec(ctx)\n\tif err != nil {\n\t\treturn errors.NewInternalf(errors.CodeInternal, \"error creating routing policies: %v\", err)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/alertmanager/nfmanager/nfroutingstore/sqlroutingstore/store.go#L11-L47","documentation":"Thrown by the SQL routing-policy store when a Bun ORM NewSelect on route_policies fails for a reason other than 'no rows' (that case is mapped to CodeNotFound). It wraps the underlying database error with CodeInternal, meaning the query itself broke: connection issues, context cancellation, or schema/model mismatch.","triggerScenarios":"Calling GetByID(ctx, orgId, id) on the routing policy store while the database is unreachable, the query context is cancelled/timed out, or the route_policies table schema doesn't match the routeTypes.RoutePolicy model (e.g. after a migration that hasn't run).","commonSituations":"DB credentials or connectivity misconfigured in the SigNoz deployment; pending database migrations after an upgrade; the org_id column value passed doesn't match expected format causing a driver-level type error; context deadline exceeded under load.","solutions":["Check the wrapped underlying error (err) in logs — it names the real cause (connection refused, no such table, cancelled context)","Verify the database is reachable and migrations for the routing policy table have been applied","Confirm orgId and id are valid non-empty strings of the expected type/UUID format","Retry once the transient DB issue (restart, failover, connection pool exhaustion) is resolved"],"exampleFix":"// before\nroute, err := store.GetByID(ctx, orgId, id)\nif err != nil { return err }\n\n// after\nroute, err := store.GetByID(ctx, orgId, id)\nif err != nil {\n\tif errors.Is(err, errors.CodeNotFound) { // handle missing policy\n\t\treturn fmt.Errorf(\"policy not found: %s\", id)\n\t}\n\treturn fmt.Errorf(\"internal db error fetching policy %s: %w\", id, err)\n}","handlingStrategy":"try-catch","validationCode":"if id == \"\" || orgId == \"\" { return errors.New(\"id and orgId are required\") }","typeGuard":"func isNotFoundErr(err error) bool { return err != nil && strings.Contains(err.Error(), \"does not exist\") }","tryCatchPattern":"route, err := store.GetByID(ctx, orgId, id)\nif err != nil {\n\tif isNotFoundErr(err) { /* 404 path */ }\n\treturn fmt.Errorf(\"fetch policy %s: %w\", id, err)\n}","preventionTips":["Keep DB migrations in sync with the app version","Use request contexts with sensible timeouts","Validate id/orgId format before querying"],"tags":["database","sql","alertmanager","routing-policy","internal"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}