Skip to main content

workyard_core/
problem_code.rs

1/// Machine-readable classification carried by a Workyard problem.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum ProblemCode {
4	/// No task matches the requested name.
5	TaskUnknown,
6	/// The requested membership change would leave the task without participants.
7	EmptyTask,
8	/// The operation requires a choice or explicit consent to continue.
9	DecisionRequired,
10	/// Creating the target branch would collide with an existing branch.
11	BranchExists,
12	/// Another worktree already has the requested branch checked out.
13	BranchInUse,
14	/// The caller requested cancellation.
15	Cancelled,
16	/// Stored data could not be validated or reconciled.
17	DamagedState,
18	/// The repository's default starting branch could not be determined.
19	DefaultBranchUnknown,
20	/// Git reported an unsuccessful exit.
21	GitFailed,
22	/// Git output exceeded the limit for reliable inspection.
23	GitOutputLimit,
24	/// The stored format or required state capability is unsupported.
25	IncompatibleState,
26	/// Git returned data the adapter could not interpret.
27	InvalidGitOutput,
28	/// An argument or combination of arguments is invalid.
29	InvalidInput,
30	/// The supplied name cannot be used for a participant directory.
31	InvalidParticipantName,
32	/// The selected Git remote is invalid for this repository.
33	InvalidRemote,
34	/// The proposed task name is invalid.
35	InvalidTask,
36	/// The supervised process could not start.
37	LaunchFailed,
38	/// Multiple participants would occupy the same task-local name.
39	ParticipantNameConflict,
40	/// A participant needs an explicit task-local name.
41	ParticipantNameRequired,
42	/// The requested locations overlap in an unsupported way.
43	PathOverlap,
44	/// Several discovered repositories match the project selector.
45	ProjectAmbiguous,
46	/// No discovered project matches the selector.
47	ProjectUnknown,
48	/// A write may be visible but its final publication could not be confirmed.
49	PublicationUncertain,
50	/// The operation requires an unambiguous remote selection.
51	RemoteRequired,
52	/// Multiple selections resolve to the same backing repository.
53	RepositoryAliasConflict,
54	/// The observed repository or worktree no longer matches expectations.
55	RepositoryChanged,
56	/// Another operation may still own the resource.
57	ResourceBusy,
58	/// Data could not be encoded for storage or delivery.
59	SerializationFailed,
60	/// The requested branch starting point could not be resolved.
61	SourceMissing,
62	/// The named filesystem entry no longer matches its expected identity.
63	StaleIdentity,
64	/// The process supervisor could not establish a reliable command outcome.
65	SupervisionFailed,
66	/// The requested task or its destination is already occupied.
67	TaskExists,
68	/// No initialized workspace was found for the supplied location.
69	WorkspaceNotFound,
70	/// Workspace state and requested workspace placement disagree.
71	WorkspaceBindingConflict,
72	/// An operating-system I/O operation failed.
73	IoError,
74}
75
76impl ProblemCode {
77	/// Return the stable spelling used in records or output.
78	pub fn as_str(self) -> &'static str {
79		match self {
80			Self::EmptyTask => "empty_task",
81			Self::TaskUnknown => "task_unknown",
82			Self::DecisionRequired => "decision_required",
83			Self::BranchExists => "branch_exists",
84			Self::BranchInUse => "branch_in_use",
85			Self::Cancelled => "cancelled",
86			Self::DamagedState => "damaged_state",
87			Self::DefaultBranchUnknown => "default_branch_unknown",
88			Self::GitFailed => "git_failed",
89			Self::GitOutputLimit => "git_output_limit",
90			Self::IncompatibleState => "incompatible_state",
91			Self::InvalidGitOutput => "invalid_git_output",
92			Self::InvalidInput => "invalid_input",
93			Self::InvalidParticipantName => "invalid_participant_name",
94			Self::InvalidRemote => "invalid_remote",
95			Self::InvalidTask => "invalid_task",
96			Self::LaunchFailed => "launch_failed",
97			Self::ParticipantNameConflict => "participant_name_conflict",
98			Self::ParticipantNameRequired => "participant_name_required",
99			Self::PathOverlap => "path_overlap",
100			Self::ProjectAmbiguous => "project_ambiguous",
101			Self::ProjectUnknown => "project_unknown",
102			Self::PublicationUncertain => "publication_uncertain",
103			Self::RemoteRequired => "remote_required",
104			Self::RepositoryAliasConflict => "repository_alias_conflict",
105			Self::RepositoryChanged => "repository_changed",
106			Self::ResourceBusy => "resource_busy",
107			Self::SerializationFailed => "serialization_failed",
108			Self::SourceMissing => "source_missing",
109			Self::StaleIdentity => "stale_identity",
110			Self::SupervisionFailed => "supervision_failed",
111			Self::TaskExists => "task_exists",
112			Self::WorkspaceNotFound => "workspace_not_found",
113			Self::WorkspaceBindingConflict => "workspace_binding_conflict",
114			Self::IoError => "io_error",
115		}
116	}
117}
118
119impl std::fmt::Display for ProblemCode {
120	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121		f.write_str(self.as_str())
122	}
123}
124
125impl std::str::FromStr for ProblemCode {
126	type Err = ();
127
128	fn from_str(value: &str) -> Result<Self, Self::Err> {
129		match value {
130			"empty_task" => Ok(Self::EmptyTask),
131			"task_unknown" => Ok(Self::TaskUnknown),
132			"decision_required" => Ok(Self::DecisionRequired),
133			"branch_exists" => Ok(Self::BranchExists),
134			"branch_in_use" => Ok(Self::BranchInUse),
135			"cancelled" => Ok(Self::Cancelled),
136			"damaged_state" => Ok(Self::DamagedState),
137			"default_branch_unknown" => Ok(Self::DefaultBranchUnknown),
138			"git_failed" => Ok(Self::GitFailed),
139			"git_output_limit" => Ok(Self::GitOutputLimit),
140			"incompatible_state" => Ok(Self::IncompatibleState),
141			"invalid_git_output" => Ok(Self::InvalidGitOutput),
142			"invalid_input" => Ok(Self::InvalidInput),
143			"invalid_participant_name" => Ok(Self::InvalidParticipantName),
144			"invalid_remote" => Ok(Self::InvalidRemote),
145			"invalid_task" => Ok(Self::InvalidTask),
146			"launch_failed" => Ok(Self::LaunchFailed),
147			"participant_name_conflict" => Ok(Self::ParticipantNameConflict),
148			"participant_name_required" => Ok(Self::ParticipantNameRequired),
149			"path_overlap" => Ok(Self::PathOverlap),
150			"project_ambiguous" => Ok(Self::ProjectAmbiguous),
151			"project_unknown" => Ok(Self::ProjectUnknown),
152			"publication_uncertain" => Ok(Self::PublicationUncertain),
153			"remote_required" => Ok(Self::RemoteRequired),
154			"repository_alias_conflict" => Ok(Self::RepositoryAliasConflict),
155			"repository_changed" => Ok(Self::RepositoryChanged),
156			"resource_busy" => Ok(Self::ResourceBusy),
157			"serialization_failed" => Ok(Self::SerializationFailed),
158			"source_missing" => Ok(Self::SourceMissing),
159			"stale_identity" => Ok(Self::StaleIdentity),
160			"supervision_failed" => Ok(Self::SupervisionFailed),
161			"task_exists" => Ok(Self::TaskExists),
162			"workspace_not_found" => Ok(Self::WorkspaceNotFound),
163			"workspace_binding_conflict" => Ok(Self::WorkspaceBindingConflict),
164			"io_error" => Ok(Self::IoError),
165			_ => Err(()),
166		}
167	}
168}