Handle errors

Catch DrasiException and branch on stable error codes.

Engine and plugin failures are a DrasiException (or a more specific subclass). Branch on Code, not on message text. Codes live in DrasiErrorCodes. Bad arguments still throw ArgumentException. After Dispose or DisposeAsync, further calls throw ObjectDisposedException. After ShutdownAsync without dispose, native calls may throw DrasiException with ENGINE_CLOSED.

Catch by type or by code

try
{
    await drasi.AddSourceAsync("postgres", "orders", config);
}
catch (UnknownKindException ex) when (ex.Code == DrasiErrorCodes.UnknownSourceKind)
{
    Console.WriteLine($"plugin kind not loaded: {ex.Message}");
}
catch (DrasiException ex)
{
    Console.WriteLine($"{ex.Code}: {ex.Message}");
}

Exception types

DrasiException
├── ConfigException
│   └── UnknownKindException
├── SourceException
├── StreamLaggedException
└── PluginException
    ├── PluginNotFoundException
    ├── PluginCompatibilityException
    └── PluginSignatureException
TypeWhen
UnknownKindExceptionUnknown source, reaction, bootstrap, store, identity, query language, or change op
ConfigExceptionMissing required config (paths, identity, durable store, JSON shape)
SourceExceptionBad SourceChange (missing id, relation without both ends)
StreamLaggedExceptionAn IAsyncEnumerable consumer overflowed its 256-item buffer
PluginNotFoundExceptionRegistry or disk lookup failed
PluginCompatibilityExceptionPlugin SDK or core version does not match this host
PluginSignatureExceptionrequireSigned: true and the artifact was not verified

Codes

DrasiErrorCodes.All lists every code the native host may report. Common ones:

CodeTypical cause
UNKNOWN_SOURCE_KINDPlugin not loaded before AddSourceAsync(kind, ...)
NO_CSHARP_SOURCEPushChangeAsync on a plugin source, or a source that was never added
CHANGE_ID_REQUIREDSourceChange.Id missing
RELATION_REQUIRES_BOTH_ENDSRelation without both StartId and EndId
DURABLE_REQUIRES_STATE_STOREAddDurableReactionAsync without a redb store
CONFIG_INVALIDFromConfigAsync document is not an object, or a field is wrong
STREAM_LAGGEDSlow IAsyncEnumerable consumer
PLUGIN_NOT_FOUNDInstallPluginAsync or ResolvePluginAsync missed the registry
ENGINE_CLOSEDCall after shutdown