some bad git hgappened
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2025-11-26 18:40:38 +01:00
parent f75f430c14
commit d1e9435ea6
12 changed files with 697 additions and 34 deletions

1
.gitignore vendored
View File

@ -26,3 +26,4 @@ Cargo.lock
# already existing elements were commented out
#/target
testepo

574
Cargo.lock generated Normal file
View File

@ -0,0 +1,574 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "anstream"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys 0.61.2",
]
[[package]]
name = "backtrace"
version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-link",
]
[[package]]
name = "backtrace-ext"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50"
dependencies = [
"backtrace",
]
[[package]]
name = "bin_efo"
version = "0.1.0"
dependencies = [
"clap",
"lib_efo",
"miette",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "bitflags"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "clap"
version = "4.5.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "errno"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]]
name = "gimli"
version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_ci"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "lib_efo"
version = "0.1.0"
dependencies = [
"clap",
"miette",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "libc"
version = "0.2.177"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
[[package]]
name = "linux-raw-sys"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
[[package]]
name = "memchr"
version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]]
name = "miette"
version = "7.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7"
dependencies = [
"backtrace",
"backtrace-ext",
"cfg-if",
"miette-derive",
"owo-colors",
"supports-color",
"supports-hyperlinks",
"supports-unicode",
"terminal_size",
"textwrap",
"unicode-width 0.1.14",
]
[[package]]
name = "miette-derive"
version = "7.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
]
[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "owo-colors"
version = "4.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52"
[[package]]
name = "proc-macro2"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustc-demangle"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
[[package]]
name = "rustix"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.61.2",
]
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
"serde_core",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "supports-color"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6"
dependencies = [
"is_ci",
]
[[package]]
name = "supports-hyperlinks"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804f44ed3c63152de6a9f90acbea1a110441de43006ea51bcce8f436196a288b"
[[package]]
name = "supports-unicode"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2"
[[package]]
name = "syn"
version = "2.0.110"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "terminal_size"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0"
dependencies = [
"rustix",
"windows-sys 0.60.2",
]
[[package]]
name = "textwrap"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
dependencies = [
"unicode-linebreak",
"unicode-width 0.2.2",
]
[[package]]
name = "thiserror"
version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "unicode-linebreak"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-width"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-targets"
version = "0.53.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
[[package]]
name = "windows_i686_gnu"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
[[package]]
name = "windows_i686_msvc"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"

View File

@ -6,3 +6,5 @@ members = ["bin_efo", "lib_efo"]
serde = { version = "1.0.228", features = ["derive"] }
clap = { version = "4.5.51", features = ["derive"] }
thiserror = "2.0.17"
serde_json = "1.0.145"
miette = { version = "7.6.0", features = ["fancy"] }

View File

@ -8,4 +8,5 @@ lib_efo = { path = "../lib_efo" }
serde = {workspace = true}
clap = {workspace = true}
thiserror = {workspace = true}
serde_json = "1.0.145"
serde_json = {workspace = true}
miette = {workspace = true}

View File

@ -11,7 +11,7 @@ pub mod cli_epoch;
/// **Public entry point used by `efo::main`** – dispatches to the real
/// handler that lives in `crate::world::EpochManager`.
pub fn handle_cmd(cmd: cli_epoch::EpochCmd) -> Result<(), AppError> {
let main_epoch = EpochConfig::new_from_path(None)?;
let _main_epoch = EpochConfig::new_from_path(None)?;
match cmd {
cli_epoch::EpochCmd::Log(args) => handle_log(args),
cli_epoch::EpochCmd::Switch(args) => handle_switch(args),

View File

@ -3,6 +3,7 @@ use std::io::Write;
use std::{fs::File, path::Path};
use clap::Args;
use lib_efo::epoch_struct::{EpochId, EpochInfo};
use lib_efo::{epoch_struct::EpochConfig, error::EpochError};
use crate::error::AppError;
@ -15,27 +16,59 @@ pub struct InitCmd {
}
/// Init an empty repository
pub fn init(args: InitCmd) -> Result<(), AppError> {
pub fn init(args: &InitCmd) -> Result<(), AppError> {
let root = Path::new(".");
if !(read_dir(root)?.count() == 0 || args.force) {
Err(EpochError::AlreadyInitialized)?
if read_dir(root)?.count() != 0 {
Err(EpochError::FolderNotEmpty {
name: None,
show_label: None,
})?;
}
let s = serde_json::to_string_pretty(&EpochConfig::empty())
.map_err(|e| EpochError::Serde(e, "Creating config".to_owned(), ".".to_owned()))?;
init_epoch(args)?;
let s = serde_json::to_string_pretty(&EpochConfig::empty()).map_err(|e| EpochError::Serde {
source: e,
file_name: "Creating config".to_owned(),
help: None,
})?;
let path = root.join(".epoch");
if let Ok(mut f) = File::create_new(path) {
write!(f, "{}", s)?;
println!("{:?}", args);
Ok(())
} else {
Err(EpochError::AlreadyInitialized)?
Err(EpochError::AlreadyInitialized {
advice: Some(
"You must remove the .epoch configuration file manually or pick another folder"
.to_string(),
),
})?
}
}
/// Tries to init the epoch 0
fn init_epoch(args: InitCmd) -> Result<(), AppError> {
fn init_epoch(_args: &InitCmd) -> Result<(), AppError> {
let path = Path::new(".").join("0");
create_dir(path)?;
create_dir(&path).map_err(|_| EpochError::FolderNotEmpty {
name: Some(path.to_str().unwrap_or_default().to_owned()),
show_label: Some((0, 0)),
})?;
Ok(())
let json =
serde_json::to_string_pretty(&EpochInfo::empty()).map_err(|e| EpochError::Serde {
source: e,
file_name: "Creating epoch file".to_owned(),
help: None,
})?;
if let Ok(mut f) = File::create_new("0/.epochfile") {
write!(f, "{}", json)?;
Ok(())
} else {
Err(EpochError::EpochInfoWrite {
id: EpochId::new(0),
path,
help: Some(
"The .epochinfo was already present in the folder this is likely an error and shouldn't have happen".to_owned(),
),
src: None,
})?
}
}

View File

@ -4,26 +4,31 @@
//! execution: parsing, I/O, epoch logic, storage, and a catch‑all.
use lib_efo::error::{EpochError, StorageError};
use miette::Diagnostic;
use thiserror::Error;
/// All errors that can bubble up to the CLI.
#[derive(Debug, Error)]
#[derive(Debug, Error, Diagnostic)]
#[allow(dead_code)]
pub enum AppError {
/// Generic “invalid command / missing flag” – emitted by clap.
#[error("Command‑line error: {0}")]
// #[diagnostic(transparent)]
Clap(#[from] clap::Error),
/// Errors that happen when reading / writing the JSON file.
#[error("I/O error: {0}")]
// #[diagnostic(transparent)]
Io(#[from] std::io::Error),
/// Domain‑specific problems (see `EpochError`).
#[error("Epoch error: {0}")]
#[error("Epoch error:")]
#[diagnostic(transparent)]
Epoch(#[from] EpochError),
/// Storage‑layer (e.g. DB) errors.
#[error("Storage error: {0}")]
// #[diagnostic(transparent)]
Storage(#[from] StorageError),
/// Anything else we didn’t anticipate.

View File

@ -47,7 +47,7 @@ enum TopLevelCmd {
// Link(commands::link::LinkCmd),
}
fn main() -> Result<(), AppError> {
fn main() -> miette::Result<()> {
let cli = Cli::parse();
if let Err(e) = exec_dispatch(cli) {
@ -58,8 +58,9 @@ fn main() -> Result<(), AppError> {
// AppError::Storage(storage_error) => todo!(),
// AppError::Other(_) => todo!(),
// }
println!("The program didn't exit properly and returned the following error:");
println!("{}", e);
// println!("The program didn't exit properly and returned the following error:");
// println!("{}", e);
Err(e)?;
}
Ok(())
@ -68,7 +69,7 @@ fn main() -> Result<(), AppError> {
fn exec_dispatch(cli: Cli) -> Result<(), AppError> {
match cli.command {
TopLevelCmd::Init(cmd) => {
commands::init::init(cmd)?;
commands::init::init(&cmd)?;
println!("The folder was initialized as an epoch folder")
}
TopLevelCmd::Epoch(cmd) => {

View File

@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2024"
[dependencies]
serde_json = "1.0.145"
serde_json = {workspace = true}
serde = {workspace = true}
thiserror = {workspace = true}
clap = {workspace = true}
miette = {workspace = true}

View File

@ -22,7 +22,7 @@
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt, fs::read_to_string, path::Path};
use crate::error::EpochError;
use crate::{epoch_struct, error::EpochError};
/// The file written to *~/.epochconfig* that tells the CLI which
/// epoch folder is the “current” one.
@ -59,12 +59,10 @@ impl EpochConfig {
let join = Path::new(".").join(".epoch");
if join.is_file() {
let config: EpochConfig =
serde_json::from_str(&read_to_string(&join)?).map_err(|e| {
EpochError::Serde(
e,
"Config".into(),
join.to_str().unwrap_or_default().to_owned(),
)
serde_json::from_str(&read_to_string(&join)?).map_err(|e| EpochError::Serde {
source: e,
file_name: join.to_str().unwrap_or_default().to_owned(),
help: None,
})?;
Ok(config)
} else {
@ -104,6 +102,18 @@ pub struct EpochInfo {
pub summary: Option<String>,
}
impl EpochInfo {
pub fn empty() -> Self {
Self {
epoch_id: epoch_struct::EpochId::new(0),
parent_id: None,
rng_seed: 0,
tags: Vec::new(),
summary: None,
}
}
}
/// Thin type to handle EpochIds
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EpochId {

View File

@ -9,9 +9,10 @@ use std::path::PathBuf;
use thiserror::Error;
use crate::epoch_struct::EpochId;
use miette::Diagnostic;
/// Errors that can be returned by the storage layer.
#[derive(Debug, Error)]
#[derive(Debug, Error, Diagnostic)]
pub enum StorageError {
/// Problems with serialisation / deserialisation.
#[error("Data error: {0}")]
@ -34,7 +35,7 @@ pub enum StorageError {
/// The enum is deliberately *small* – each variant is self‑contained
/// and carries the information you need to surface a friendly message
/// to the user (and to the test‑suite).
#[derive(Error, Debug)]
#[derive(Error, Debug, Diagnostic)]
pub enum EpochError {
/// Problems with the `.epochconfig` file
#[error("Failed to read epoch configuration")]
@ -44,14 +45,40 @@ pub enum EpochError {
ConfigWrite(#[source] std::io::Error),
#[error("This directory is already an epoch folder and thus cannot be initialized")]
AlreadyInitialized,
#[diagnostic(code(EpochError::AlreadyInitialized))]
AlreadyInitialized {
#[help]
advice: Option<String>,
},
#[error("This directory isn't empty and thus cannot be initialized")]
#[diagnostic(code(EpochError::FolderNotEmpty))]
#[diagnostic(help("Empty the folder or remove its content first"))]
// #[diagnostic(label((1,1)))]
FolderNotEmpty {
#[source_code]
name: Option<String>,
#[label("This file is present and forbid the command to execute properly")]
show_label: Option<(usize, usize)>,
},
/// Problems while serialising / deserialising an `EpochInfo`
#[error("Failed to parse `.epochinfo` in epoch {0} ({1}): {2}")]
EpochInfoParse(EpochId, PathBuf, #[source] serde_json::Error),
#[error("Failed to write `.epochinfo` in epoch {0} ({1}): {2}")]
EpochInfoWrite(EpochId, PathBuf, #[source] std::io::Error),
#[error("Failed to write `.epochinfo` in epoch {id} ({path})")]
#[diagnostic(code(EpochError::EpochInfoWrite))]
EpochInfoWrite {
id: EpochId,
path: PathBuf,
#[help]
help: Option<String>,
#[source]
src: Option<std::io::Error>,
},
/// The user supplied an epoch id or tag that does not exist
#[error("No epoch found for id/tag `{}`", .0)]
@ -97,8 +124,17 @@ pub enum EpochError {
Io(#[source] std::io::Error),
/// Serialization / deserialization errors that are not caught above
#[error("Serialization error: {1}:{2} {0}")]
Serde(serde_json::Error, String, String),
#[error("Serialization error from {file_name}")]
#[diagnostic(code(EpochError::SerdeError))]
Serde {
#[source]
source: serde_json::Error,
file_name: String,
#[diagnostic(help)]
help: Option<String>,
},
/// The epoch tree is in an incorrect state
#[error("Invalid epoch tree at {0}")]

1
testepo/.gitignore vendored
View File

@ -1 +0,0 @@
testepo*