add_ed/error/internal.rs
1/// Defines non-user errors
2///
3/// Expected to report reaching unreachable code, over-/under-flow, etc., if
4/// such is caught. The recommendation when receiving any of these will be:
5/// "Save your work, close the editor, and create an issue at
6/// https://github.com/sidju/add-ed which describes what you did to trigger
7/// this error".
8#[derive(Debug, Clone, PartialEq)]
9pub enum InternalError {
10 /// A code path that shouldn't be reachable was reached. We use this error
11 /// instead of panic to not drop buffer without letting user save
12 UnreachableCode{file: &'static str, line: u32, column: u32},
13 /// `add-ed` internal code tried to create a line from invalid text data. This
14 /// should never occur and indicates a logic bug within `add-ed`.
15 InvalidLineText(crate::buffer::LineTextError),
16}
17
18/// A utility macro for panic free coding
19///
20/// Creates an EdError that details what went wrong where, so you can debug it
21/// when it won't drop data.
22macro_rules! ed_unreachable {
23 () => { Err(EdError::Internal(InternalError::UnreachableCode{
24 file: file!(),
25 line: line!(),
26 column: column!(),
27 })) }
28}