elsa-workflows/elsa-core · error · ArgumentException
A metadata key is required.
Error message
A metadata key is required.
What it means
ConsoleLogContextAccessor.PushMetadata stores a key/value metadata frame in the ambient log context. Both the key and the value must be non-whitespace; an empty or whitespace key throws ArgumentException naming the key parameter.
Solutions
- Pass a non-empty, non-whitespace key (and value) to PushMetadata
- Guard the call site: skip pushing when the key/value is missing instead of pushing empty strings
- Fix the upstream source (e.g. configuration) that supplies an empty metadata key
Example fix
// before
accessor.PushMetadata(config.MetadataKey!, instanceId); // MetadataKey may be empty
// after
if (!string.IsNullOrWhiteSpace(config.MetadataKey))
accessor.PushMetadata(config.MetadataKey, instanceId); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
accessor.PushMetadata(key, value); Type guard
bool CanPushMetadata(string? k, string? v) => !string.IsNullOrWhiteSpace(k) && !string.IsNullOrWhiteSpace(v);
Try / catch
try { accessor.PushMetadata(key, value); }
catch (ArgumentException ex) when (ex.ParamName is "key" or "value")
{ logger.LogWarning(ex, "Skipped empty console log metadata"); } Prevention
- Guard metadata sources for empty config values
- Never derive metadata keys from possibly-null data without checks
- Wrap metadata pushes in a helper that skips blank inputs
When it happens
Trigger: Calling PushMetadata("", value), PushMetadata(" ", value), or passing a null/whitespace key — directly or via PushWorkflowInstanceId when the workflow instance id source yields nothing and the key itself is blank.
Common situations: Programmatically building metadata keys from config values that are empty; a null instance id used as the key string; copy-paste leaving the key argument blank.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- A metadata value is required.
- The console log stream filter must be 'stdout', 'stderr'…
- The console log provider registration is invalid.
- Capacity must be greater than zero.
- Capacity must be greater than zero.
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/cff9a0d768976d96.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogContextAccessor.cs:33
private ConsoleLogContextAccessor()
{
}
/// <inheritdoc />
public IReadOnlyDictionary<string, string> GetMetadata()
{
var metadata = CurrentFrame.Value?.Metadata;
return metadata == null || metadata.Count == 0
? Empty
: new Dictionary<string, string>(metadata, StringComparer.OrdinalIgnoreCase);
}
/// <inheritdoc />
public IDisposable PushMetadata(string key, string value)
{
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentException("A metadata key is required.", nameof(key));
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("A metadata value is required.", nameof(value));
var previous = CurrentFrame.Value;
var metadata = previous?.Metadata != null
? new Dictionary<string, string>(previous.Metadata, StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
metadata[key] = value;
CurrentFrame.Value = new(metadata);
return new MetadataScope(previous);
}
/// <inheritdoc />
public IDisposable PushWorkflowInstanceId(string workflowInstanceId) =>
PushMetadata(ConsoleLogMetadataKeys.WorkflowInstanceId, workflowInstanceId);
View on GitHub (pinned to fe9217bdfa)