elsa-workflows/elsa-core · error · ArgumentException

A metadata value is required.

Error message

A metadata value is required.

What it means

ConsoleLogContextAccessor.PushMetadata validates both arguments before pushing an ambient metadata frame via AsyncLocal. It throws ArgumentException when the key or the value is null, empty, or whitespace. The accessor uses an OrdinalIgnoreCase metadata dictionary, so keys are case-insensitive but never optional.

Solutions

  1. Check string.IsNullOrWhiteSpace(value) at the call site and skip the PushMetadata call when it is empty.
  2. Coalesce the value to a placeholder (e.g. value ?? "unknown") if an entry must always be pushed.
  3. Fix the upstream source (workflow context, config, DI registration) so the instance id is populated before logging metadata.

Example fix

// before
using var _ = accessor.PushWorkflowInstanceId(instanceId);

// after
if (!string.IsNullOrWhiteSpace(instanceId))
    using var _ = accessor.PushWorkflowInstanceId(instanceId);
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))
    accessor.PushMetadata(key, value);

Try / catch

try { accessor.PushMetadata(key, value); }
catch (ArgumentException ex) { logger.LogWarning(ex, "Skipped metadata push: {Message}", ex.Message); }

Prevention

When it happens

Trigger: Calling PushMetadata(key, "") or PushMetadata(key, " "); also via wrapper methods like PushWorkflowInstanceId when a null/empty workflow instance id is passed in.

Common situations: Reading a workflow instance id from a nullable context property or configuration value that has not been populated yet, then pushing it unconditionally without a null/empty check.

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


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/509f3b7afc70ffac. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogContextAccessor.cs:36

    }

    /// <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);

    private sealed record MetadataFrame(IReadOnlyDictionary<string, string> Metadata);

    private sealed class MetadataScope(MetadataFrame? previous) : IDisposable

View on GitHub (pinned to fe9217bdfa)