screenpipe/screenpipe · error · anyhow::Error
failed to parse {} as live-view-template.v1: {error}
Error message
failed to parse {} as live-view-template.v1: {error} What it means
After reading the file, 'view apply' deserializes its bytes as a LiveViewTemplate via serde_json. If the JSON is invalid or does not match the live-view-template.v1 schema (wrong fields, wrong types, missing required fields), the serde error is wrapped in this message naming the file and schema version.
Source
Thrown at crates/screenpipe-engine/src/cli/view.rs:48
view.revision,
view.blocks.len()
);
}
}
}
ViewCommand::Show { id, json, data_dir } => {
let view = get_live_view(&resolve_data_dir(data_dir), id)?;
if *json {
println!("{}", serde_json::to_string_pretty(&view)?);
} else {
print_view_summary(&view);
}
}
ViewCommand::Apply { file, data_dir } => {
let bytes = std::fs::read(file)
.map_err(|error| anyhow::anyhow!("failed to read {}: {error}", file.display()))?;
let template: LiveViewTemplate = serde_json::from_slice(&bytes).map_err(|error| {
anyhow::anyhow!(
"failed to parse {} as live-view-template.v1: {error}",
file.display()
)
})?;
let view = apply_live_view_template(&resolve_data_dir(data_dir), template)?;
println!(
"applied Live View '{}' (revision {})",
view.title, view.revision
);
}
ViewCommand::Delete { id, data_dir } => {
delete_live_view(&resolve_data_dir(data_dir), id)?;
println!("deleted Live View '{id}'");
}
ViewCommand::Export {
id,
format,
output,View on GitHub (pinned to 4ebf712990)
Solutions
- Export the template as JSON (ViewExportFormat::Json) before applying.
- Validate the file with a JSON parser/linter and fix syntax errors.
- Compare the JSON structure against a known-good live-view-template.v1 export and fix field names/types.
- Restore an unmodified export instead of the hand-edited file.
Example fix
// before (invalid: missing name field)
{"id":"abc123","rows":[]}
// after
{"id":"abc123","name":"My View","rows":[]} Defensive patterns
Strategy: validation
Validate before calling
const raw = await Deno.readTextFile(file);
let json;
try { json = JSON.parse(raw); } catch (e) { throw new Error(`${file} is not valid JSON: ${e.message}`); }
if (json == null || typeof json !== 'object' || Array.isArray(json)) throw new Error(`${file} is not a template object`);
for (const key of ['id', 'name']) if (!(key in json)) throw new Error(`${file} missing required field '${key}' (live-view-template.v1)`); Type guard
function isLiveViewTemplate(v) {
return v != null && typeof v === 'object' && !Array.isArray(v) &&
typeof v.id === 'string' && typeof v.name === 'string';
} Try / catch
try {
applyViewTemplate(file);
} catch (e) {
if (String(e).includes('live-view-template.v1')) {
console.error(`${file} is not a valid live-view-template.v1 JSON export; re-export the view as JSON`);
} else throw e;
} Prevention
- Only apply files exported with --format json, never HTML/Markdown exports.
- Validate JSON with a linter before applying hand-edited templates.
- Keep schema changes in sync between app versions before exchanging templates.
- Keep a pristine copy of exports separate from edited versions.
When it happens
Trigger: Applying a file that is not valid JSON (trailing commas, HTML/markdown exported instead of JSON); a JSON file with a schema mismatch — renamed fields, missing required 'id'/'name', wrong value types; hand-edited template that broke the structure.
Common situations: Exporting as HTML/Markdown then trying to apply that file; editing the exported JSON and introducing a type error; applying a template from a newer/older app version with an incompatible schema.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- OAuth client registration returned invalid JSON: {}
- OAuth refresh endpoint returned invalid JSON: {}
- parsing recording settings from {}: {e}
- recording settings did not serialize to an object
- managed Pipe API response has no pipes array
AI-assisted analysis of screenpipe/screenpipe@4ebf712990 (2026-09-01).
Data as JSON: /api/errors/e44db299b7b57ef1.
Report an issue: GitHub.