GraphiteEditor/Graphite · error

Failed to parse document

Error message

Failed to parse document

What it means

graph-craft's load_network parses the raw .graphite document text with serde_json; this first from_str fails when the content is not valid JSON at all. The file was read successfully, but its bytes do not form a JSON document.

Source

Thrown at node-graph/graph-craft/src/util.rs:6

use crate::document::NodeNetwork;
use crate::graphene_compiler::Compiler;
use crate::proto::ProtoNetwork;

pub fn load_network(document_string: &str) -> NodeNetwork {
	let document: serde_json::Value = serde_json::from_str(document_string).expect("Failed to parse document");
	let document = (document["network_interface"]["network"].clone()).to_string();
	serde_json::from_str::<NodeNetwork>(&document).expect("Failed to parse document")
}

pub fn compile(network: NodeNetwork) -> ProtoNetwork {
	let compiler = Compiler {};
	compiler.compile_single(network).unwrap()
}

pub fn load_from_name(name: &str) -> NodeNetwork {
	let content = std::fs::read(format!("../../demo-artwork/{name}.graphite")).expect("failed to read file");
	let content = std::str::from_utf8(&content).unwrap();
	load_network(content)
}

pub static DEMO_ART: [&str; 7] = [
	"changing-seasons",
	"painted-dreams",

View on GitHub (pinned to c507b35645)

Solutions

  1. Validate the file with jq or any JSON linter before passing it in
  2. Parse via serde_json::from_str::<serde_json::Value> (or serde_path_to_error) first to get a precise position message
  3. Re-export the artwork from the editor to regenerate clean JSON

Example fix

// before
let document: serde_json::Value = serde_json::from_str(document_string).expect("Failed to parse document");

// after
let document: serde_json::Value = serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(document_string))
	.unwrap_or_else(|e| panic!("Failed to parse document at {}: {e}", e.path()));
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_json(text: &str) -> bool {
	serde_json::from_str::<serde_json::Value>(text).is_ok()
}

Try / catch

match serde_json::from_str::<serde_json::Value>(document_string) {
	Ok(v) => v,
	Err(e) => return Err(format!("document is not valid JSON: {e}")),
}

Prevention

When it happens

Trigger: load_from_name reading a truncated or corrupted ../../demo-artwork/*.graphite file; a name resolving to a path containing non-JSON content; a download that saved an HTML error page with a .graphite extension.

Common situations: Incomplete LFS checkouts in CI; hand-editing documents and breaking JSON syntax; UTF-16 or BOM-prefixed exports from other tools.

Understand the failure class

Related errors


AI-assisted analysis of GraphiteEditor/Graphite@c507b35645 (2026-08-16). Data as JSON: /api/errors/793dddbba0e65082. Report an issue: GitHub.