clankerdiff_core/
error.rs1#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5pub enum RepoPathError {
6 #[error("repository path is empty")]
7 Empty,
8 #[error("repository path contains a NUL byte")]
10 Nul,
11 #[error("repository path must be relative")]
13 Absolute,
14 #[error("repository path contains '.' or '..' component")]
16 Traversal,
17}
18
19impl From<std::convert::Infallible> for RepoPathError {
20 fn from(value: std::convert::Infallible) -> Self {
21 match value {}
22 }
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
26#[error("unknown diff scope `{0}`; expected unstaged, staged, or both")]
27pub struct ParseDiffScopeError(pub String);
28
29#[derive(Debug, thiserror::Error)]
31pub enum DiffError {
32 #[error("unsupported path encoding: {0}")]
34 UnsupportedPathEncoding(#[source] std::str::Utf8Error),
35 #[error("invalid repository path: {0}")]
37 InvalidPath(#[from] RepoPathError),
38 #[error("failed to parse diff: {source}")]
40 Parse {
41 #[source]
43 source: diffy::patch_set::PatchSetParseError,
44 },
45 #[error("invalid UTF-8: {0}")]
47 Utf8(#[from] std::str::Utf8Error),
48 #[error("invalid git porcelain v1 record")]
50 InvalidPorcelainEntry,
51}
52
53impl From<std::string::FromUtf8Error> for DiffError {
54 fn from(error: std::string::FromUtf8Error) -> Self {
55 Self::UnsupportedPathEncoding(error.utf8_error())
56 }
57}