abiosoft/colima · error

error marshaling store: %w

Error message

error marshaling store: %w

What it means

save() serializes the Store with json.MarshalIndent before writing it to disk; this error means that serialization failed. The Store is plain bool/string data, so in practice this is near-unreachable — hitting it indicates the Store type gained a JSON-unsupported member (chan, func, complex, cyclic reference) or a custom MarshalJSON that returns an error.

Source

Thrown at store/store.go:42

// Load loads the store from the json file.
func Load() (s Store, err error) {
	b, err := os.ReadFile(storeFile())
	if err != nil {
		return s, fmt.Errorf("cannot read store file: %w", err)
	}

	if err := json.Unmarshal(b, &s); err != nil {
		return s, fmt.Errorf("error unmarshaling store file: %w", err)
	}

	return s, nil
}

// save persists the store.
func save(s Store) error {
	b, err := json.MarshalIndent(s, "", "  ")
	if err != nil {
		return fmt.Errorf("error marshaling store: %w", err)
	}

	if err := os.WriteFile(storeFile(), b, 0o644); err != nil {
		return fmt.Errorf("error writing store file: %w", err)
	}

	return nil
}

// Set provides an easy way to set a value in the store.
func Set(f func(*Store)) error {
	s, err := Load()
	if err != nil {
		logrus.Debug("error loading store: %w", err)
	}

	f(&s)

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Inspect the Store struct for fields json cannot encode (chan, func, complex, self-referencing pointers) and fix or tag them json:"-"
  2. Add a unit test that round-trips Store through json.Marshal and back
  3. If a custom MarshalJSON exists, exercise its error path

Example fix

// before
type Store struct {
	RamalamaProvisioned bool
	Events chan struct{} // not JSON-serializable
}

// after
type Store struct {
	RamalamaProvisioned bool
	Events chan struct{} `json:"-"` // excluded from serialization
}
Defensive patterns

Strategy: try-catch

Try / catch

var unsupported *json.UnsupportedTypeError
if errors.As(err, &unsupported) {
	// a Store field type is not serializable: fix the struct — retrying will not help
}

Prevention

When it happens

Trigger: A code change adds a channel/func field or cyclic pointer to Store and any store.Set persists; a custom MarshalJSON implementation returns an error for some state.

Common situations: Forks or contributions refactoring Store without a serialization round-trip test.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/b3e4b1c4586ca003. Report an issue: GitHub.