Skip to main content

ralph/
error_messages.rs

1//! Canonical error message constructors.
2//!
3//! Responsibilities:
4//! - Provide helper functions for all "task not found" error scenarios
5//! - Ensure consistent formatting and actionable hints
6//!
7//! Does not handle:
8//! - Error types (use anyhow/thiserror in consuming modules)
9//! - I18N (messages are English-only)
10//!
11//! Invariants/assumptions:
12//! - All task ID parameters are non-empty trimmed strings
13//! - Messages include actionable hints where appropriate
14
15/// Task not found in the active queue only.
16pub fn task_not_found_in_queue(task_id: &str) -> String {
17    format!("Task '{task_id}' not found in active queue.")
18}
19
20/// Task not found in either queue or done archive.
21pub fn task_not_found_in_queue_or_done(task_id: &str) -> String {
22    format!("Task '{task_id}' not found in queue or done archive.")
23}
24
25/// Task not found with hint to use --include-done.
26pub fn task_not_found_with_include_done_hint(task_id: &str) -> String {
27    format!(
28        "Task '{task_id}' not found in active queue. \
29         Use --include-done to search the done archive."
30    )
31}
32
33/// Root task not found (for tree/graph commands).
34pub fn root_task_not_found(task_id: &str, include_done: bool) -> String {
35    if include_done {
36        format!("Root task '{task_id}' not found in queue or done archive.")
37    } else {
38        format!(
39            "Root task '{task_id}' not found in active queue. \
40             Use --include-done to search the done archive."
41        )
42    }
43}
44
45/// Source task not found (for clone/split operations).
46pub fn source_task_not_found(task_id: &str, search_done: bool) -> String {
47    if search_done {
48        format!("Source task '{task_id}' not found in queue or done archive.")
49    } else {
50        format!("Source task '{task_id}' not found in active queue.")
51    }
52}
53
54/// Task not found for batch operations (recorded as failure).
55pub fn task_not_found_batch_failure(task_id: &str) -> String {
56    format!("Task not found: {task_id}")
57}
58
59/// Task not found with operation context (for QueueQueryError).
60pub fn task_not_found_with_operation(operation: &str, task_id: &str) -> String {
61    format!(
62        "Queue query failed (operation={operation}): \
63         target task not found: {task_id}. \
64         Ensure it exists in .ralph/queue.jsonc."
65    )
66}
67
68/// Task not found in done archive specifically.
69pub fn task_not_found_in_done_archive(task_id: &str, context: &str) -> String {
70    format!("Task '{task_id}' not found in done archive for {context}.")
71}
72
73/// Task not found for edit operations with file context.
74pub fn task_not_found_for_edit(operation: &str, task_id: &str) -> String {
75    format!(
76        "Queue {operation} failed (task_id={task_id}): \
77         task not found in .ralph/queue.jsonc."
78    )
79}
80
81/// Generic task not found (for simple cases).
82pub fn task_not_found(task_id: &str) -> String {
83    format!("Task not found: {task_id}")
84}
85
86/// Task no longer exists (for session recovery scenarios).
87/// Used when a task was deleted during execution.
88pub fn task_no_longer_exists(task_id: &str) -> String {
89    format!("Task '{task_id}' no longer exists in queue (may have been deleted or archived).")
90}