insertJson5 method

void insertJson5(
  1. String key,
  2. String value
)

Inserts a JSON5 value at the given configuration key path.

JSON5 string values require inner quotes, e.g.:

config.insertJson5('mode', '"peer"');

Throws ZenohException if the key is invalid or the value is rejected. Throws StateError if the config has been disposed or consumed.

⚠️ The message may echo your config text. On the unstable variant it carries canon's own words for the failure, and canon's json5 parser echoes the offending value and the surrounding source line — adjacent intact secrets included — with a caret pointing at the offending token. Do not forward this message into a log, a crash report or a bug report without deciding redaction first. No redaction is applied here; see ZenohException.enriched for why a general one is not implementable at this seam. On the default stable variant no upstream detail is carried at all, so the message is the base text alone.

⛔ This is the site where the echo is widest: the value you passed is exactly what canon is complaining about, so it is exactly what comes back.

Implementation

void insertJson5(String key, String value) {
  _ensureNotDisposed();
  _ensureNotConsumed();
  final nativeKey = key.toNativeUtf8();
  final nativeValue = value.toNativeUtf8();
  try {
    final result = _withDetailBuffer(
      (errBuf, errCap, errLen) => bindings.zd_config_insert_json5(
        _ptr.cast(),
        nativeKey.cast(),
        nativeValue.cast(),
        errBuf,
        errCap,
        errLen,
      ),
    );
    if (result.rc != 0) {
      // Detail-carrying site: the message canon produced for THIS call
      // came back from the call itself, in storage this frame supplied.
      throw ZenohException.enriched(
        'Failed to insert config value for key "$key"',
        result.rc,
        result.detail,
      );
    }
  } finally {
    malloc
      ..free(nativeKey)
      ..free(nativeValue);
  }
}