aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 00:52:20 +0000
committertv <tv@krebsco.de>2026-12-01 00:52:20 +0000
commit30eb9a31ec7e4cf0ef683c86edb28ffc6fa3d54e (patch)
tree82a3abb64b8ca02f79a76121d3f3a38c82f4fece /src
parent54f070ef0f905f867a24dece72f667be23f9f843 (diff)
enstate: --pack warns of an entry from text with placeholders
Text loses its trailing line breaks, which a key or a certificate rarely should; a whole-value source (cmd:…, file:…, or a table) takes an entry byte-exact. The warning says so, and the entry goes in as asked.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs4
-rw-r--r--src/pack.rs15
2 files changed, 15 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 8d3830b..5ae94e1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -229,7 +229,9 @@ fn run() -> Result<ExitCode> {
if command == "pack" {
let out = out.context("--pack needs --out DIR")?;
let schema = settings.schema.as_deref().map(Schema::load).transpose()?;
- enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())?;
+ for warning in enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())? {
+ eprintln!("enstate: warning: {warning}");
+ }
return Ok(ExitCode::SUCCESS);
}
let store = Store::new(
diff --git a/src/pack.rs b/src/pack.rs
index 67603d6..dda4f6a 100644
--- a/src/pack.rs
+++ b/src/pack.rs
@@ -78,8 +78,9 @@ impl SourceList {
}
/// Packs the source list at `path` into a submission in `out` (which must not exist,
-/// or be empty), checked against `schema` if one is given.
-pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> {
+/// or be empty), checked against `schema` if one is given. Returns warnings: an
+/// entry whose source is text with placeholders loses its trailing line breaks.
+pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<Vec<String>> {
let list = SourceList::load(path)?;
let dir = path
.parent()
@@ -104,10 +105,18 @@ pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> {
let mut entries: BTreeMap<String, Vec<u8>> = BTreeMap::new();
let mut records: BTreeMap<String, Map<String, Value>> = BTreeMap::new();
let mut specs = Vec::new();
+ let mut warnings = Vec::new();
for (address, item) in &items {
if let Some(source) = &item.source {
let importer = importer(source, &dir, address.key.is_none())
.with_context(|| format!("item {address}"))?;
+ if address.key.is_none() && importer.is_interpolation() {
+ warnings.push(format!(
+ "item {address}: its source is text with placeholders, which loses \
+ trailing line breaks; for the entry as it is, a whole-value source \
+ (cmd:…, file:…, or a table) takes it byte-exact"
+ ));
+ }
let imported = importer
.fetch()
.with_context(|| format!("item {address}: {}", importer.describe()))?;
@@ -169,7 +178,7 @@ pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> {
content::write_file(&out.join(submission::MANIFEST), &manifest_bytes, 0o600)?;
// What was written is a submission the receptor reads.
submission::Submission::load(out)?;
- Ok(())
+ Ok(warnings)
}
/// The importer `source` describes, in `dir`: raw for an entry, JSON for a record.