validateInterceptionCursor checks that a pagination cursor refers to an existing interception. When sessionID is non-empty the interception must also belong to that session. Returns errInvalidCursor on failure so callers can distinguish bad cursors from internal errors.
(ctx context.Context, db database.Store, cursorID uuid.UUID, cursorName, sessionID string)
| 637 | // also belong to that session. Returns errInvalidCursor on failure so |
| 638 | // callers can distinguish bad cursors from internal errors. |
| 639 | func validateInterceptionCursor(ctx context.Context, db database.Store, cursorID uuid.UUID, cursorName, sessionID string) error { |
| 640 | if cursorID == uuid.Nil { |
| 641 | return nil |
| 642 | } |
| 643 | interception, err := db.GetAIBridgeInterceptionByID(ctx, cursorID) |
| 644 | if err != nil { |
| 645 | return xerrors.Errorf("%s: interception %s not found: %w", cursorName, cursorID, errInvalidCursor) |
| 646 | } |
| 647 | if sessionID != "" && interception.SessionID != sessionID { |
| 648 | return xerrors.Errorf("%s: interception %s does not belong to session %s: %w", cursorName, cursorID, sessionID, errInvalidCursor) |
| 649 | } |
| 650 | return nil |
| 651 | } |
| 652 | |
| 653 | func populatedAndConvertAIBridgeInterceptions(ctx context.Context, db database.Store, dbInterceptions []database.ListAIBridgeInterceptionsRow) ([]codersdk.AIBridgeInterception, error) { |
| 654 | if len(dbInterceptions) == 0 { |
no test coverage detected