Skip to main content

grex_core/lockfile/
entry.rs

1//! Lockfile entry + error types.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7/// One resolved pack entry. Serialized as a single JSON line.
8#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
9pub struct LockEntry {
10    /// Pack identifier — matches the manifest id.
11    pub id: String,
12    /// Resolved commit SHA at the time of install.
13    pub sha: String,
14    /// Branch or ref used to resolve `sha`.
15    pub branch: String,
16    /// Timestamp of the last successful install/sync.
17    pub installed_at: DateTime<Utc>,
18    /// Content hash of the declarative actions that ran. Empty for
19    /// imperative packs.
20    pub actions_hash: String,
21    /// Schema version of this entry.
22    pub schema_version: String,
23}
24
25/// Errors surfaced by lockfile read/write.
26#[derive(Debug, Error)]
27pub enum LockfileError {
28    /// I/O failure while reading or writing.
29    #[error("lockfile i/o error: {0}")]
30    Io(#[from] std::io::Error),
31
32    /// A line failed to parse. Lockfile corruption is always fatal — there
33    /// is no torn-line recovery rule since writes are atomic.
34    #[error("lockfile corrupted at line {line}: {source}")]
35    Corruption {
36        /// 1-based line number.
37        line: usize,
38        /// Underlying JSON parse error.
39        #[source]
40        source: serde_json::Error,
41    },
42
43    /// Serialization failure when writing.
44    #[error("lockfile serialize error: {0}")]
45    Serialize(serde_json::Error),
46}