Config.fromFile constructor
- String path
Creates a configuration from a JSON5 file at path.
The resulting config has the same lifecycle as a default Config: it may
be passed to Session.open (which consumes it) or disposed.
Throws ZenohException (enriched with upstream detail where available)
if path cannot be read or does not contain valid config JSON5.
The _from_file_substr substring variant is carved (equivalent-by-design
to this null-terminated form); not bound.
⚠️ 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.
Implementation
factory Config.fromFile(String path) {
final nativePath = path.toNativeUtf8();
try {
return Config._build(
'Failed to create config from file "$path"',
(ptr, errBuf, errCap, errLen) => bindings.zd_config_from_file(
ptr.cast(),
nativePath.cast(),
errBuf,
errCap,
errLen,
),
);
} finally {
malloc.free(nativePath);
}
}