{"record":{"id":"e44db299b7b57ef1","repo":"screenpipe/screenpipe","slug":"failed-to-parse-as-live-view-template-v1-erro","errorCode":null,"errorMessage":"failed to parse {} as live-view-template.v1: {error}","messagePattern":"failed to parse (.+?) as live-view-template\\.v1: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/screenpipe-engine/src/cli/view.rs","lineNumber":48,"sourceCode":"                        view.revision,\n                        view.blocks.len()\n                    );\n                }\n            }\n        }\n        ViewCommand::Show { id, json, data_dir } => {\n            let view = get_live_view(&resolve_data_dir(data_dir), id)?;\n            if *json {\n                println!(\"{}\", serde_json::to_string_pretty(&view)?);\n            } else {\n                print_view_summary(&view);\n            }\n        }\n        ViewCommand::Apply { file, data_dir } => {\n            let bytes = std::fs::read(file)\n                .map_err(|error| anyhow::anyhow!(\"failed to read {}: {error}\", file.display()))?;\n            let template: LiveViewTemplate = serde_json::from_slice(&bytes).map_err(|error| {\n                anyhow::anyhow!(\n                    \"failed to parse {} as live-view-template.v1: {error}\",\n                    file.display()\n                )\n            })?;\n            let view = apply_live_view_template(&resolve_data_dir(data_dir), template)?;\n            println!(\n                \"applied Live View '{}' (revision {})\",\n                view.title, view.revision\n            );\n        }\n        ViewCommand::Delete { id, data_dir } => {\n            delete_live_view(&resolve_data_dir(data_dir), id)?;\n            println!(\"deleted Live View '{id}'\");\n        }\n        ViewCommand::Export {\n            id,\n            format,\n            output,","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/screenpipe/screenpipe/blob/4ebf712990fee17eeaf904dacf749b6e96ac9bf3/crates/screenpipe-engine/src/cli/view.rs#L30-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (invalid: missing name field)\n{\"id\":\"abc123\",\"rows\":[]}\n// after\n{\"id\":\"abc123\",\"name\":\"My View\",\"rows\":[]}","handlingStrategy":"validation","validationCode":"const raw = await Deno.readTextFile(file);\nlet json;\ntry { json = JSON.parse(raw); } catch (e) { throw new Error(`${file} is not valid JSON: ${e.message}`); }\nif (json == null || typeof json !== 'object' || Array.isArray(json)) throw new Error(`${file} is not a template object`);\nfor (const key of ['id', 'name']) if (!(key in json)) throw new Error(`${file} missing required field '${key}' (live-view-template.v1)`);","typeGuard":"function isLiveViewTemplate(v) {\n  return v != null && typeof v === 'object' && !Array.isArray(v) &&\n    typeof v.id === 'string' && typeof v.name === 'string';\n}","tryCatchPattern":"try {\n  applyViewTemplate(file);\n} catch (e) {\n  if (String(e).includes('live-view-template.v1')) {\n    console.error(`${file} is not a valid live-view-template.v1 JSON export; re-export the view as JSON`);\n  } else throw e;\n}","preventionTips":["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."],"tags":["json","serde","schema-validation","cli"],"backgroundTag":"schema-validation-failed","analyzedSha":"4ebf712990fee17eeaf904dacf749b6e96ac9bf3","analyzedAt":"2026-09-01T23:33:43.065Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}