aboutsummaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-02-22 18:37:43 +0100
committerGitHub <noreply@github.com>2021-02-22 18:37:43 +0100
commita9d943e2d93be0e741874cb1ef85488dacc6eeab (patch)
treee6591f07da1455d170d5c20c1f49beeeefcd5bbd /src/error.rs
parent02bb836d9a9261b0ba9eb5ef6a9f02cc3605b672 (diff)
parent7b2dd8497967bb2a78f7ff2055a4976a9bb2a4e5 (diff)
downloadsylt-a9d943e2d93be0e741874cb1ef85488dacc6eeab.tar.gz
Merge pull request #87 from FredTheDino/conflict-markers
Detect conflict markers
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/error.rs b/src/error.rs
index c2ad228..9aca985 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -32,6 +32,8 @@ pub enum ErrorKind {
/// (line, token)
SyntaxError(usize, Token),
+ /// (start, end)
+ GitConflictError(usize, usize),
}
#[derive(Debug, Clone)]
@@ -67,9 +69,8 @@ impl fmt::Display for ErrorKind {
write!(f, "Argument types do not match, expected [{:?}] but got [{:?}]",
expected, given)
}
- ErrorKind::IndexOutOfBounds(value, len, slot) => {
- write!(f, "Failed to index for {:?} - length is {} but index is {}",
- value, len, slot)
+ ErrorKind::IndexError(value, slot) => {
+ write!(f, "Cannot index value '{:?}' with type '{:?}'.", value, slot)
}
ErrorKind::ExternTypeMismatch(name, types) => {
write!(f, "Extern function '{}' doesn't accept argument(s) with type(s) {:?}",
@@ -81,27 +82,32 @@ impl fmt::Display for ErrorKind {
.fold(String::new(), |a, v| { format!("{}{:?}, ", a, v) });
write!(f, "Cannot apply {:?} to values {}", op, values)
}
- ErrorKind::AssertFailed => {
- write!(f, "Assertion failed")
+ ErrorKind::UnknownField(obj, field) => {
+ write!(f, "Cannot find field '{}' on {:?}", field, obj)
}
- ErrorKind::SyntaxError(line, token) => {
- write!(f, "Syntax Error on line {} at token {:?}", line, token)
+ ErrorKind::ArgumentCount(expected, given) => {
+ write!(f, "Incorrect argument count, expected {} but got {}.",
+ expected, given)
}
- ErrorKind::Unreachable => {
- write!(f, "Reached unreachable code.")
+ ErrorKind::IndexOutOfBounds(value, len, slot) => {
+ write!(f, "Failed to index for {:?} - length is {} but index is {}",
+ value, len, slot)
+ }
+ ErrorKind::AssertFailed => {
+ write!(f, "Assertion failed")
}
ErrorKind::InvalidProgram => {
write!(f, "{}", "[!!] Invalid program [!!]".bold())
}
- ErrorKind::IndexError(value, slot) => {
- write!(f, "Cannot index value '{:?}' with type '{:?}'.", value, slot)
+ ErrorKind::Unreachable => {
+ write!(f, "Reached unreachable code.")
}
- ErrorKind::UnknownField(obj, field) => {
- write!(f, "Cannot find field '{}' on {:?}", field, obj)
+ ErrorKind::SyntaxError(line, token) => {
+ write!(f, "Syntax Error on line {} at token {:?}", line, token)
}
- ErrorKind::ArgumentCount(expected, given) => {
- write!(f, "Incorrect argument count, expected {} but got {}.",
- expected, given)
+ ErrorKind::GitConflictError(start_line, end_line) => {
+ write!(f, "Git conflict markers found between lines {} and {}",
+ start_line, end_line)
}
}
}
@@ -109,7 +115,7 @@ impl fmt::Display for ErrorKind {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let prompt = "*****".red();
+ let prompt = " ";
let message = match &self.message {
Some(s) => format!("\n{} {}", prompt, s),
None => String::from(""),
@@ -123,7 +129,7 @@ impl fmt::Display for Error {
String::new()
};
- write!(f, "\n {} {}:{} \n{} {}{}{}\n", "ERR".red(),
+ write!(f, "{} {}:{}\n{} {}{}{}", "ERROR".red(),
self.file.display().blue(), self.line.blue(), prompt, self.kind, message, line)
}
}