( taskID string, req contract.CreateTaskBlockRequest, claimToken string, )
| 2412 | } |
| 2413 | |
| 2414 | func createTaskBlockFromRequest( |
| 2415 | taskID string, |
| 2416 | req contract.CreateTaskBlockRequest, |
| 2417 | claimToken string, |
| 2418 | ) (taskpkg.BlockRequest, error) { |
| 2419 | blockReq := taskpkg.BlockRequest{ |
| 2420 | TaskID: strings.TrimSpace(taskID), |
| 2421 | Kind: req.Kind.Normalize(), |
| 2422 | Reason: strings.TrimSpace(req.Reason), |
| 2423 | Details: cloneRawMessage(req.Details), |
| 2424 | RunID: strings.TrimSpace(req.RunID), |
| 2425 | ClaimToken: strings.TrimSpace(claimToken), |
| 2426 | } |
| 2427 | if req.ExpiresAt != nil { |
| 2428 | blockReq.ExpiresAt = req.ExpiresAt.UTC() |
| 2429 | } |
| 2430 | if blockReq.TaskID == "" { |
| 2431 | return taskpkg.BlockRequest{}, fmt.Errorf("%w: task_block.task_id is required", taskpkg.ErrValidation) |
| 2432 | } |
| 2433 | if err := blockReq.Kind.Validate("task_block.kind"); err != nil { |
| 2434 | return taskpkg.BlockRequest{}, err |
| 2435 | } |
| 2436 | if blockReq.Reason == "" { |
| 2437 | return taskpkg.BlockRequest{}, fmt.Errorf("%w: task_block.reason is required", taskpkg.ErrValidation) |
| 2438 | } |
| 2439 | if blockReq.ExpiresAt.IsZero() { |
| 2440 | return blockReq, nil |
| 2441 | } |
| 2442 | if blockReq.Kind != taskpkg.BlockKindTransient { |
| 2443 | return taskpkg.BlockRequest{}, fmt.Errorf( |
| 2444 | "%w: task_block.expires_at is only valid for %q blocks", |
| 2445 | taskpkg.ErrValidation, |
| 2446 | taskpkg.BlockKindTransient, |
| 2447 | ) |
| 2448 | } |
| 2449 | return blockReq, nil |
| 2450 | } |
| 2451 | |
| 2452 | func statusForTaskBlockError(err error) int { |
| 2453 | if errors.Is(err, taskpkg.ErrValidation) { |
no test coverage detected