1pub mod academic;
2pub mod cli;
3#[cfg(feature = "evaluation")]
4pub mod evaluation;
5pub mod lexical;
6pub mod lint;
7pub mod morphology;
8pub mod outline;
9pub mod terms;
10mod text;
11
12use std::path::Path;
13
14use thiserror::Error;
15
16#[derive(Debug, Error)]
17pub enum Error {
18 #[error("エラー: ファイルが見つかりません: {0}")]
19 NotFound(String),
20 #[error("エラー: ファイルではありません: {0}")]
21 NotAFile(String),
22 #[error("エラー: ファイルを読み込めません: {path} ({source})")]
23 Read {
24 path: String,
25 #[source]
26 source: std::io::Error,
27 },
28 #[error("エラー: 形態素解析器を初期化できません: {0}")]
29 Morphology(String),
30 #[error("エラー: JSONを処理できません: {0}")]
31 Json(#[from] serde_json::Error),
32 #[error("エラー: 設定ファイルを処理できません: {path} ({message})")]
33 Config { path: String, message: String },
34 #[error("エラー: {0}")]
35 InvalidArguments(String),
36 #[error("エラー: 学術監査に失敗しました: {0}")]
37 Academic(String),
38}
39
40pub fn read_source(path: &Path) -> Result<String, Error> {
41 if !path.exists() {
42 return Err(Error::NotFound(path.display().to_string()));
43 }
44 if !path.is_file() {
45 return Err(Error::NotAFile(path.display().to_string()));
46 }
47 std::fs::read_to_string(path).map_err(|source| Error::Read {
48 path: path.display().to_string(),
49 source,
50 })
51}