Skip to content

nodespace-types::SchemaNode::from_node silently swallows a schema field parse failure to an empty Vec #2107

Closed

Description

@mstomar125

Context

While implementing the SchemaField.friendly_name split, a review of the write-boundary defaulting mechanism surfaced two structurally identical, pre-existing bugs: SchemaField deserialization failures inside a schema node's fields array are silently swallowed to an empty Vec, with no error surfaced and (in one of the two cases) no log line.

Both sites build a Vec<SchemaField> the same way:

let fields: Vec<SchemaField> = node
    .properties
    .get("fields")
    .and_then(|v| serde_json::from_value(v.clone()).ok())
    .unwrap_or_default();
  • packages/core/src/models/schema_node.rs::SchemaNode::from_node — used by SqliteStore::get_schema_node/get_all_schemas, the backend storage-layer schema fetch (core and user-created schemas alike, no is_core distinction in the query). Fixed in the friendly_name PR: now logs a tracing::warn! on parse failure instead of silently producing an empty Vec.
  • packages/nodespace-types/src/schema.rs::SchemaNode::from_node (a distinct struct/impl of the same name) — used by packages/nodespace-types/src/convert.rs::node_to_typed_value, which its own doc comment calls "the single canonical implementation used by all entry points (Tauri commands, MCP, HTTP)". Not fixed — nodespace-types deliberately carries no logging dependency (verified: no tracing/log in its Cargo.toml), so the same fix can't just be copy-pasted here without either adding a dependency to a crate whose whole design goal is a minimal dependency footprint, or restructuring how the error surfaces.

This is arguably the more consequential of the two sites — it's what an end user's UI or an MCP client actually sees for any generic node read that happens to be a schema node — and it remains completely silent on a genuine parse failure: a schema with malformed/legacy field data reads back with 0 fields, nowhere in any log.

Why this matters (not hypothetical)

  • The friendly_name field itself is #[serde(default)]-tolerant, so a missing friendlyName key doesn't trigger this path. But any OTHER kind of malformed field JSON (a genuinely corrupted value, a future required-field addition without a serde default, a type mismatch) still silently drops every field on the schema with zero diagnostic signal on this path.
  • Both this class of bug and the general shape of "seeded/stored content doesn't survive a structural change to what a reader expects" have already bitten this repo once (see the 06a94eee reseed-mechanism commit, closes #1812) — worth closing off the analogous gap here before something similarly non-obvious ships on top of it.

Suggested approaches (pick one — not prescribing)

  1. Thread the error through Result. nodespace_types::SchemaNode::from_node already returns Result<Self, String> — instead of swallowing the field-parse failure internally, propagate it as the function's own error. Callers with logging capability (the Tauri command layer, the daemon, the MCP layer) already handle a Result from node_to_typed_value and could log there. Caution: nodes_to_typed_values currently .collect()s a Vec<Result<_, _>> into a single Result<Vec<_>, _> — a single bad schema node would fail an entire batch read that also contains unrelated nodes, which may be an undesirable blast-radius change and needs deliberate consideration, not a reflexive fix.
  2. Give nodespace-types a minimal, dependency-free diagnostic hook — e.g. a #[cfg]-gated eprintln! behind a feature flag, or a caller-supplied callback/closure parameter threaded through from_node, so a consuming crate that does have logging can opt in without forcing a new dependency onto a crate whose entire design goal is a minimal footprint.
  3. Do nothing to nodespace-types itself, add a narrower guard downstream — e.g. a debug-assertion or startup healthcheck that flags any schema node with a non-empty properties.fields JSON key but a resulting empty typed fields array, run periodically or on daemon start, without touching the crate's dependency graph at all.

Acceptance criteria

  • A parse failure in nodespace_types::SchemaNode::from_node's fields extraction is surfaced somewhere actionable (a log line, a propagated error, or an equivalent diagnostic) rather than silently producing an empty Vec
  • Any behavior change to node_to_typed_value's error-propagation shape (if approach 1 is chosen) is deliberately evaluated against nodes_to_typed_values's batch-collect semantics, not a reflexive ?
  • nodespace-types's minimal-dependency design goal (documented in its own crate-level doc comment) is respected by whichever approach is chosen

Activity

  1. mstomar125 commented on Aug 18, 2026

    @mstomar125
    ContributorAuthor

    Resolved in #2128.

    Chose approach 2 (a minimal, dependency-free diagnostic hook): SchemaNode::from_node's fields extraction now delegates to a private parse_fields helper that returns the field list alongside an optional diagnostic message, printed via eprintln! when the parse genuinely fails — no new dependency, no from_node signature change.

    Approach 1 (thread the error through Result) was evaluated and deliberately rejected, not reflexively avoided: node_to_typed_value is the sole caller of this from_node, and it's what nodes_to_typed_values maps over via .collect::<Result<Vec<_>, _>>() across ~10 batch-read call sites in core/desktop-app/daemon. Propagating the fields-parse failure as an Err would fail an entire unrelated batch read over one bad schema node — exactly the blast-radius risk the issue flagged. A new regression test in convert.rs (schema_with_malformed_fields_does_not_fail_an_unrelated_batch_read) pins that this batch-safety property holds.

    Approach 3 (downstream guard, don't touch nodespace-types) was also rejected: a debug-assertion/startup healthcheck only catches this at dev/CI time or daemon boot, not for a schema read mid-session — it doesn't close the "silently, everywhere" gap the issue is about.

    Full reasoning and diff in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions