comparison rust/rhg/src/error.rs @ 46505:b274aa2f20fd

rust: remove three enums that were identical to `RevlogError` Differential Revision: https://phab.mercurial-scm.org/D9877
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 26 Jan 2021 20:42:36 +0100
parents 252d1bdba33d
children 776b97179c06
comparison
equal deleted inserted replaced
46504:252d1bdba33d 46505:b274aa2f20fd
1 use crate::exitcode; 1 use crate::exitcode;
2 use crate::ui::utf8_to_local; 2 use crate::ui::utf8_to_local;
3 use crate::ui::UiError; 3 use crate::ui::UiError;
4 use format_bytes::format_bytes; 4 use format_bytes::format_bytes;
5 use hg::operations::{ 5 use hg::operations::{FindRootError, ListDirstateTrackedFilesError};
6 CatRevError, DebugDataError, FindRootError, ListDirstateTrackedFilesError,
7 ListRevTrackedFilesError,
8 };
9 use hg::requirements::RequirementsError; 6 use hg::requirements::RequirementsError;
7 use hg::revlog::revlog::RevlogError;
10 use hg::utils::files::get_bytes_from_path; 8 use hg::utils::files::get_bytes_from_path;
11 use std::convert::From; 9 use std::convert::From;
12 use std::path::PathBuf; 10 use std::path::PathBuf;
13 11
14 /// The kind of command error 12 /// The kind of command error
97 } 95 }
98 } 96 }
99 } 97 }
100 } 98 }
101 99
102 impl From<(DebugDataError, &str)> for CommandError { 100 impl From<(RevlogError, &str)> for CommandError {
103 fn from((err, rev): (DebugDataError, &str)) -> CommandError { 101 fn from((err, rev): (RevlogError, &str)) -> CommandError {
104 match err { 102 match err {
105 DebugDataError::IoError(err) => CommandError::Abort(Some( 103 RevlogError::IoError(err) => CommandError::Abort(Some(
106 utf8_to_local(&format!("abort: {}\n", err)).into(), 104 utf8_to_local(&format!("abort: {}\n", err)).into(),
107 )), 105 )),
108 DebugDataError::InvalidRevision => CommandError::Abort(Some( 106 RevlogError::InvalidRevision => CommandError::Abort(Some(
109 utf8_to_local(&format!( 107 utf8_to_local(&format!(
110 "abort: invalid revision identifier{}\n", 108 "abort: invalid revision identifier {}\n",
111 rev 109 rev
112 )) 110 ))
113 .into(), 111 .into(),
114 )), 112 )),
115 DebugDataError::AmbiguousPrefix => CommandError::Abort(Some( 113 RevlogError::AmbiguousPrefix => CommandError::Abort(Some(
116 utf8_to_local(&format!( 114 utf8_to_local(&format!(
117 "abort: ambiguous revision identifier{}\n", 115 "abort: ambiguous revision identifier {}\n",
118 rev 116 rev
119 )) 117 ))
120 .into(), 118 .into(),
121 )), 119 )),
122 DebugDataError::UnsuportedRevlogVersion(version) => { 120 RevlogError::UnsuportedVersion(version) => {
123 CommandError::Abort(Some( 121 CommandError::Abort(Some(
124 utf8_to_local(&format!( 122 utf8_to_local(&format!(
125 "abort: unsupported revlog version {}\n", 123 "abort: unsupported revlog version {}\n",
126 version 124 version
127 )) 125 ))
128 .into(), 126 .into(),
129 )) 127 ))
130 } 128 }
131 DebugDataError::CorruptedRevlog => { 129 RevlogError::Corrupted => {
132 CommandError::Abort(Some("abort: corrupted revlog\n".into())) 130 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
133 } 131 }
134 DebugDataError::UnknowRevlogDataFormat(format) => { 132 RevlogError::UnknowDataFormat(format) => {
135 CommandError::Abort(Some(
136 utf8_to_local(&format!(
137 "abort: unknow revlog dataformat {:?}\n",
138 format
139 ))
140 .into(),
141 ))
142 }
143 }
144 }
145 }
146
147 impl From<(ListRevTrackedFilesError, &str)> for CommandError {
148 fn from((err, rev): (ListRevTrackedFilesError, &str)) -> CommandError {
149 match err {
150 ListRevTrackedFilesError::IoError(err) => CommandError::Abort(
151 Some(utf8_to_local(&format!("abort: {}\n", err)).into()),
152 ),
153 ListRevTrackedFilesError::InvalidRevision => {
154 CommandError::Abort(Some(
155 utf8_to_local(&format!(
156 "abort: invalid revision identifier {}\n",
157 rev
158 ))
159 .into(),
160 ))
161 }
162 ListRevTrackedFilesError::AmbiguousPrefix => {
163 CommandError::Abort(Some(
164 utf8_to_local(&format!(
165 "abort: ambiguous revision identifier {}\n",
166 rev
167 ))
168 .into(),
169 ))
170 }
171 ListRevTrackedFilesError::UnsuportedRevlogVersion(version) => {
172 CommandError::Abort(Some(
173 utf8_to_local(&format!(
174 "abort: unsupported revlog version {}\n",
175 version
176 ))
177 .into(),
178 ))
179 }
180 ListRevTrackedFilesError::CorruptedRevlog => {
181 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
182 }
183 ListRevTrackedFilesError::UnknowRevlogDataFormat(format) => {
184 CommandError::Abort(Some(
185 utf8_to_local(&format!(
186 "abort: unknow revlog dataformat {:?}\n",
187 format
188 ))
189 .into(),
190 ))
191 }
192 }
193 }
194 }
195
196 impl From<(CatRevError, &str)> for CommandError {
197 fn from((err, rev): (CatRevError, &str)) -> CommandError {
198 match err {
199 CatRevError::IoError(err) => CommandError::Abort(Some(
200 utf8_to_local(&format!("abort: {}\n", err)).into(),
201 )),
202 CatRevError::InvalidRevision => CommandError::Abort(Some(
203 utf8_to_local(&format!(
204 "abort: invalid revision identifier {}\n",
205 rev
206 ))
207 .into(),
208 )),
209 CatRevError::AmbiguousPrefix => CommandError::Abort(Some(
210 utf8_to_local(&format!(
211 "abort: ambiguous revision identifier {}\n",
212 rev
213 ))
214 .into(),
215 )),
216 CatRevError::UnsuportedRevlogVersion(version) => {
217 CommandError::Abort(Some(
218 utf8_to_local(&format!(
219 "abort: unsupported revlog version {}\n",
220 version
221 ))
222 .into(),
223 ))
224 }
225 CatRevError::CorruptedRevlog => {
226 CommandError::Abort(Some("abort: corrupted revlog\n".into()))
227 }
228 CatRevError::UnknowRevlogDataFormat(format) => {
229 CommandError::Abort(Some( 133 CommandError::Abort(Some(
230 utf8_to_local(&format!( 134 utf8_to_local(&format!(
231 "abort: unknow revlog dataformat {:?}\n", 135 "abort: unknow revlog dataformat {:?}\n",
232 format 136 format
233 )) 137 ))