/ src / error.rs
error.rs
  1  //! Errors returned from functions in this crate.
  2  
  3  use std::path::PathBuf;
  4  
  5  #[derive(Debug, thiserror::Error)]
  6  pub enum JournalError {
  7      /// Configuration file does not exist.
  8      #[error("specified configuration file does not exist: {0}")]
  9      ConfigMissing(PathBuf),
 10  
 11      /// Failed to read the configuration file.
 12      ///
 13      /// This is for permission problems and such.
 14      #[error("failed to read configuration file {0}")]
 15      ReadConfig(PathBuf, #[source] std::io::Error),
 16  
 17      /// Configuration file has a syntax error.
 18      #[error("failed to understand configuration file syntax: {0}")]
 19      ConfigSyntax(PathBuf, #[source] serde_yaml::Error),
 20  
 21      /// The specified directory does not look like a journal.
 22      #[error("directory {0} is not a journal")]
 23      NotAJournal(String),
 24  
 25      /// The specified directory for the journal does not exist.
 26      #[error("journal directory does not exist: {0}")]
 27      NoJournalDirectory(PathBuf),
 28  
 29      /// Failed to create the directory for the journal.
 30      #[error("failed to create journal directory {0}")]
 31      CreateDirectory(PathBuf, #[source] std::io::Error),
 32  
 33      /// Failed to rename entry when finishing it.
 34      #[error("failed to rename journal entry {0} to {1}: {2}")]
 35      RenameEntry(PathBuf, PathBuf, #[source] std::io::Error),
 36  
 37      /// Failed to rename draft.
 38      #[error("failed to remove draft {0}: {1}")]
 39      RemoveDraft(PathBuf, #[source] std::io::Error),
 40  
 41      /// Failed to write entry.
 42      #[error("failed to create journal entry {0}: {1}")]
 43      WriteEntry(PathBuf, #[source] std::io::Error),
 44  
 45      /// Failed to write topic page.
 46      #[error("failed to create topic page {0}: {1}")]
 47      WriteTopic(PathBuf, #[source] std::io::Error),
 48  
 49      /// User chose a draft that doesn't exist.
 50      #[error("No draft {0} in {1}")]
 51      NoSuchDraft(String, PathBuf),
 52  
 53      /// Too many drafts.
 54      #[error("there are already {0} drafts in {1}, can't create more")]
 55      TooManyDrafts(usize, PathBuf),
 56  
 57      /// User chose a topic that doesn't exist.
 58      #[error("No topic page {0}")]
 59      NoSuchTopic(PathBuf),
 60  
 61      /// Failed to read draft.
 62      #[error("failed to drafts {0}: {1}")]
 63      ReadDraft(PathBuf, #[source] std::io::Error),
 64  
 65      /// Draft is not UTF8.
 66      #[error("draft {0} is not UTF8: {1}")]
 67      DraftNotUUtf8(PathBuf, #[source] std::string::FromUtf8Error),
 68  
 69      /// Failed to get metadata for specific file in drafts folder.
 70      #[error("failed to stat draft in {0}: {1}")]
 71      StatDraft(PathBuf, #[source] std::io::Error),
 72  
 73      /// Error spawning git.
 74      #[error("failed to start git in {0}: {1}")]
 75      SpawnGit(PathBuf, std::io::Error),
 76  
 77      /// Git init failed.
 78      #[error("git init failed in {0}: {1}")]
 79      GitInit(PathBuf, String),
 80  
 81      /// Git add failed.
 82      #[error("git add failed in {0}: {1}")]
 83      GitAdd(PathBuf, String),
 84  
 85      /// Git commit failed.
 86      #[error("git commit failed in {0}: {1}")]
 87      GitCommit(PathBuf, String),
 88  
 89      /// Error spawning editor.
 90      #[error("failed to start editor {0} on file {1}")]
 91      SpawnEditor(String, PathBuf, #[source] std::io::Error),
 92  
 93      /// Editor failed.
 94      #[error("editor {0} failed: {1}")]
 95      EditorFailed(PathBuf, String),
 96  
 97      /// Template not found.
 98      #[error("template not found: {0}")]
 99      TemplateNotFound(String),
100  
101      /// Failed to render a Tera template.
102      #[error("template {0} failed to render: {1}")]
103      TemplateRender(String, #[source] tera::Error),
104  
105      /// Failed to make a path relative to a directory.
106      #[error("failed to make {0} relative to {1}: {2}")]
107      RelativePath(PathBuf, PathBuf, std::path::StripPrefixError),
108  
109      /// Problem with glob pattern.
110      #[error("Error in glob pattern {0}: {1}")]
111      PatternError(String, #[source] glob::PatternError),
112  
113      /// Problem when matching glob pattern on actual files.
114      #[error("Failed to match glob pattern {0}: {1}")]
115      GlobError(String, #[source] glob::GlobError),
116  }