disk-type

A value read from a node's disk does not have the type of the default given to `disk.Read`.

run error, shown by synod run.

disk.Read k on n or d returns the value stored under k, or d when nothing is stored. The default fixes the type of the result, so what is stored has to be accepted as that type. A list stored where a map is expected is not.

Example

Run this program to see the diagnostic.

# package main
use example.com/explain/p
use std/sim

define main
  set a to (sim.Spawn p)
  after 1s
    sim.Remove a
# package p
use std/disk

Node has
  set Pages to {}

define [n: Node] start
  disk.Write {"a"} at "pages" on n
  set n.Pages to (disk.Read "pages" on n or {})
  set item "k" of n.Pages to "v"

Diagnostic

failed at 0s: p/p.synod:9:19: error[disk-type]: disk value at "pages" is a list of text, not a map of text to text

Fix

Write the same kind of value that the default has.

# package main
use example.com/explain/p
use std/sim

define main
  set a to (sim.Spawn p)
  after 1s
    sim.Remove a
# package p
use std/disk

Node has
  set Pages to {}

define [n: Node] start
  set m to {}
  set item "a" of m to "b"
  disk.Write m at "pages" on n
  set n.Pages to (disk.Read "pages" on n or {})
  set item "k" of n.Pages to "v"