MCPcopy Index your code
hub / github.com/coder/coder / fetchTaskWithFallback

Function fetchTaskWithFallback

coderd/httpmw/taskparam.go:85–108  ·  view source on GitHub ↗
(ctx context.Context, db database.Store, taskParam string, ownerID uuid.UUID)

Source from the content-addressed store, hash-verified

83}
84
85func 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}

Callers 1

ExtractTaskParamFunction · 0.85

Calls 5

ParseMethod · 0.65
GetTaskByIDMethod · 0.65
IsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected