summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 36d8f077ab06b56ae386e83ed691704d1b82ee24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Errors returned from functions in this crate.

use std::path::PathBuf;

#[derive(Debug, thiserror::Error)]
pub enum JournalError {
    /// Configuration file does not exist.
    #[error("specified configuration file does not exist: {0}")]
    ConfigMissing(PathBuf),

    /// Failed to read the configuration file.
    ///
    /// This is for permission problems and such.
    #[error("failed to read configuration file {0}")]
    ReadConfig(PathBuf, #[source] std::io::Error),

    /// Configuration file has a syntax error.
    #[error("failed to understand configuration file syntax: {0}")]
    ConfigSyntax(PathBuf, #[source] serde_yaml::Error),

    /// The specified directory does not look like a journal.
    #[error("directory {0} is not a journal")]
    NotAJournal(String),

    /// Failed to create the directory for the journal.
    #[error("failed to create journal directory {0}")]
    CreateDirectory(PathBuf, #[source] std::io::Error),

    /// Failed to rename entry when finishing it.
    #[error("failed to rename journal entry {0} to {1}: {2}")]
    RenameEntry(PathBuf, PathBuf, #[source] std::io::Error),

    /// Failed to write entry.
    #[error("failed to create journal entry {0}: {1}")]
    WriteEntry(PathBuf, #[source] std::io::Error),

    /// Failed to write topic page.
    #[error("failed to create topic page {0}: {1}")]
    WriteTopic(PathBuf, #[source] std::io::Error),

    /// User chose a draft that doesn't exist.
    #[error("No draft {0} in {1}")]
    NoSuchDraft(String, PathBuf),

    /// Too many drafts.
    #[error("there are already {0} drafts in {1}, can't create more")]
    TooManyDrafts(usize, PathBuf),

    /// User chose a topic that doesn't exist.
    #[error("No topic page {0}")]
    NoSuchTopic(PathBuf),

    /// Failed to read draft.
    #[error("failed to drafts {0}: {1}")]
    ReadDraft(PathBuf, #[source] std::io::Error),

    /// Draft is not UTF8.
    #[error("draft {0} is not UTF8: {1}")]
    DraftNotUUtf8(PathBuf, #[source] std::string::FromUtf8Error),

    /// Failed to get metadata for specific file in drafts folder.
    #[error("failed to stat draft in {0}: {1}")]
    StatDraft(PathBuf, #[source] std::io::Error),

    /// Error spawning git.
    #[error("failed to start git in {0}: {1}")]
    SpawnGit(PathBuf, std::io::Error),

    /// Git init failed.
    #[error("git init failed in {0}: {1}")]
    GitInit(PathBuf, String),

    /// Git add failed.
    #[error("git add failed in {0}: {1}")]
    GitAdd(PathBuf, String),

    /// Git commit failed.
    #[error("git commit failed in {0}: {1}")]
    GitCommit(PathBuf, String),

    /// Error spawning editor.
    #[error("failed to start editor {0}: {1}")]
    SpawnEditor(PathBuf, #[source] std::io::Error),

    /// Editor failed.
    #[error("editor {0} failed: {1}")]
    EditorFailed(PathBuf, String),

    /// Template not found.
    #[error("template not found: {0}")]
    TemplateNotFound(String),

    /// Failed to render a Tera template.
    #[error("template {0} failed to render: {1}")]
    TemplateRender(String, #[source] tera::Error),

    /// Failed to make a path relative to a directory.
    #[error("failed to make {0} relative to {1}: {2}")]
    RelativePath(PathBuf, PathBuf, std::path::StripPrefixError),

    /// Problem with glob pattern.
    #[error("Error in glob pattern {0}: {1}")]
    PatternError(String, #[source] glob::PatternError),

    /// Problem when matching glob pattern on actual files.
    #[error("Failed to match glob pattern {0}: {1}")]
    GlobError(String, #[source] glob::GlobError),
}