(ctx context.Context, db database.Store, taskParam string, ownerID uuid.UUID)
| 83 | } |
| 84 | |
| 85 | func fetchTaskWithFallback(ctx context.Context, db database.Store, taskParam string, ownerID uuid.UUID) (database.Task, error) { |
| 86 | // Attempt to first lookup the task by UUID. |
| 87 | taskID, err := uuid.Parse(taskParam) |
| 88 | if err == nil { |
| 89 | task, err := db.GetTaskByID(ctx, taskID) |
| 90 | if err == nil { |
| 91 | return task, nil |
| 92 | } |
| 93 | // There may be a task named with a valid UUID. Fall back to name lookup in this case. |
| 94 | if !errors.Is(err, sql.ErrNoRows) { |
| 95 | return database.Task{}, xerrors.Errorf("fetch task by uuid: %w", err) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // taskParam not a valid UUID, OR valid UUID but not found, so attempt lookup by name. |
| 100 | task, err := db.GetTaskByOwnerIDAndName(ctx, database.GetTaskByOwnerIDAndNameParams{ |
| 101 | OwnerID: ownerID, |
| 102 | Name: taskParam, |
| 103 | }) |
| 104 | if err != nil { |
| 105 | return database.Task{}, xerrors.Errorf("fetch task by name: %w", err) |
| 106 | } |
| 107 | return task, nil |
| 108 | } |
no test coverage detected