siyuan-note/siyuan · error

entry [ ]

Error message

entry [%s]: %w

What it means

When decoding a JSON object into a map-typed contract field, decodeRequestValue wraps any failure for a specific key as "entry [%s]: %w" with the offending key name. It means one value inside the map failed the strict decoder for the map's element type. The wrapped cause from the recursive decode is preserved.

Solutions

  1. Fix the entry named in the error so its value matches the map's declared value type
  2. Omit invalid entries from the map before sending
  3. Coerce values client-side (String(v), Boolean(v)) to the expected type
  4. Verify the map value type in the endpoint's contract definition

Example fix

// before
attrs: { "name": "a", "memo": null }
// after
attrs: { "name": "a", "memo": "" }
Defensive patterns

Strategy: validation

Validate before calling

function validateMap(obj, check) {
  for (const [k, v] of Object.entries(obj)) { if (!check(v)) throw new Error(`entry [${k}] invalid`); }
}
validateMap(payload.attrs, (v) => typeof v === "string");

Type guard

const allValuesOfType = (o, t) => Object.values(o).every((v) => typeof v === t);

Try / catch

try { await fetchPost(url, payload); } catch (e) { const m = String(e).match(/entry \[([^\]]+)]/); if (m) console.error("Bad map entry:", m[1]); }

Prevention

When it happens

Trigger: Sending a map field (e.g. kramdown doc mapping, custom attribute maps) where one entry's value does not decode into the map's value type — e.g. {"key": null} for a map[string]string field, or nested wrong types.

Common situations: Building maps dynamically in JavaScript where a value ended up null/undefined; sending attributes objects with mixed value types; version drift where the contract narrowed the map value type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/177849230ad35c14. Report an issue: GitHub.

Appendix: source

Thrown at kernel/apicontract/decode.go:205

			return err
		}
		value.Set(reflect.MakeSlice(value.Type(), len(entries), len(entries)))
		for i, entry := range entries {
			if err := decodeRequestValue(entry, value.Index(i)); err != nil {
				return fmt.Errorf("element [%d]: %w", i, err)
			}
		}
		return nil
	case reflect.Map:
		var entries map[string]json.RawMessage
		if err := json.Unmarshal(raw, &entries); err != nil {
			return err
		}
		value.Set(reflect.MakeMapWithSize(value.Type(), len(entries)))
		for key, entry := range entries {
			child := reflect.New(value.Type().Elem()).Elem()
			if err := decodeRequestValue(entry, child); err != nil {
				return fmt.Errorf("entry [%s]: %w", key, err)
			}
			value.SetMapIndex(reflect.ValueOf(key).Convert(value.Type().Key()), child)
		}
		return nil
	default:
		return json.Unmarshal(raw, value.Addr().Interface())
	}
}

View on GitHub (pinned to 9f775e8a12)