1use super::*;
2
3impl std::fmt::Display for EdError {
4 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5 use EdError::*;
6 match self {
7 Internal(e) => write!(f,
8 "Internal error! Save and quit, and please report at {}\n\n debug data: {:?}",
9 "`https://github.com/sidju/add-ed/issues`",
10 e,
11 ),
12 IO(e) => write!(f,
13 "IO error: {}",
14 e.inner,
15 ),
16 UI(e) => write!(f,
17 "UI error: {}",
18 e.inner,
19 ),
20
21 InfiniteRecursion => write!(f,
22 "Execution recursion hit recursion limit, no changes made."
23 ),
24
25 IndexTooBig{index, buffer_len} => {
26 if *buffer_len == 0 {
27 write!(f,
28 "Buffer is empty, so no valid selections or lines can exist.",
29 )
30 } else {
31 write!(f,
32 "Given index ({}) overshoots the length of the buffer ({}).",
33 index,
34 buffer_len,
35 )
36 }
37 },
38 Line0Invalid => write!(f,
39 "Index 0 was given when a line was needed, there is no line at index 0."
40 ),
41 SelectionEmpty(s) => write!(f,
42 "Selection given ({},{}) is empty or inverted.",
43 s.0, s.1,
44 ),
45 SelectionForbidden => write!(f,
46 "That command doesn't allow any selection."
47 ),
48
49 UnsavedChanges => write!(f,
50 "Unsaved changes! Capitalise command to ignore.",
51 ),
52 NoOp => write!(f,
53 "That combination of command and arguments doesn't do anything.",
54 ),
55 UndoIndexNegative{relative_undo_limit} => write!(f,
56 "Tried to undo to before undo history.\nHighest valid nr of undo steps is {}.",
57 relative_undo_limit,
58 ),
59 UndoIndexTooBig{index, history_len, relative_redo_limit} => write!(f,
60 "Tried to redo beyond existing snapshots.\nHigest valid nr of redo steps is {}.\n(Given index: {}, Highest valid index: {})",
61 relative_redo_limit,
62 index,
63 history_len - 1,
64 ),
65 CommandEscapeForbidden(_path) => write!(f,
66 "Command doesn't accept shell escapes. Use \\! if path begins with !.",
67 ),
68 TagInvalid(args) => write!(f,
69 "Invalid tag given: {}. Tags should be a single character.",
70 args,
71 ),
72 TagNoMatch(t) => write!(f,
73 "Could not find any line matching the tag `{}`.",
74 t,
75 ),
76 RegexInvalid{regex, error} => write!(f,
77 "Regex `{}` invalid! {}.",
78 regex,
79 error,
80 ),
81 RegexNoMatch(regex) => write!(f,
82 "No matches found for regex `{}`.",
83 regex,
84 ),
85 PrintAfterWipe => write!(f,
86 "Would print after deleting whole buffer, refusing to run command.",
87 ),
88
89 DefaultFileUnset => write!(f,
90 "Couldn't read default file as it hasn't been set. Set by opening file or with the `f` command.",
91 ),
92 DefaultShellCommandUnset => write!(f,
93 "Couldn't read default shell command as it hasn't been set. Run a fully defined shell command first.",
94 ),
95 DefaultSArgsUnset => write!(f,
96 "Couldn't read default `s` arguments as they haven't been set. Run `s` with arguments first.",
97 ),
98
99 IndexSpecialAfterStart{prior_index, special_index} => write!(f,
100 "Special index character `{}` found after index `{}`.",
101 special_index,
102 prior_index,
103 ),
104 IndexNotInt(text) => write!(f,
105 "Failed to parse given index string `{}` as a number.",
106 text,
107 ),
108 OffsetNotInt(text) => write!(f,
109 "Failed to parse given index offset `{}` as a number.",
110 text,
111 ),
112 IndicesUnrelated{prior_index, unrelated_index} => write!(f,
113 "Received non-chainable index `{}` immediately after index `{}`.",
114 unrelated_index,
115 prior_index,
116 ),
117 IndexUnfinished(text) => write!(f,
118 "Special index unfinished: `{}`.",
119 text,
120 ),
121
122 CommandUndefined(cmd) => write!(f,
123 "Unknown command `{}`.",
124 cmd,
125 ),
126 ArgumentListEscapedEnd(arguments) => write!(f,
127 "Argument list's end was escaped: `{}`.",
128 arguments,
129 ),
130 ArgumentsWrongNr{expected, received} => write!(f,
131 "Wrong nr of arguments given. Expected {}, received {}.",
132 expected,
133 received,
134 ),
135 ScrollNotInt(text) => write!(f,
136 "Failed to parse nr of lines to scroll `{}` as a number.",
137 text,
138 ),
139 UndoStepsNotInt(text) => write!(f,
140 "Failed to parse nr of changes to undo/redo `{}` as a number.",
141 text,
142 ),
143 ReflowNotInt{error: e, text: t} => write!(f,
144 "Failed to parse nr of columns to reflow within `{}` as a number: {}",
145 t,
146 e,
147 ),
148 MacroUndefined(macro_name) => write!(f,
149 "Given macro `{}` is not defined.",
150 macro_name,
151 ),
152
153 FlagDuplicate(flag) => write!(f,
154 "Flag `{}` was given more than once.",
155 flag,
156 ),
157 FlagUndefined(flag) => write!(f,
158 "Given flag `{}` isn't valid for that command.",
159 flag,
160 ),
161 }
162 }
163}