elsa-workflows/elsa-core · error · JsonException

Unsupported console stream value

Error message

Unsupported console stream value '{value}'.

What it means

ConsoleStreamJsonConverter.Write serializes a ConsoleStream value. The enum is expected to contain only Stdout and Stderr; any other value (defaulted, corrupted, or future enum member) cannot be mapped to a JSON string, so it throws JsonException.

Solutions

  1. Only assign ConsoleStream.Stdout or ConsoleStream.Stderr; check the value before serializing
  2. Fix any raw int casts to validate via Enum.IsDefined first
  3. Align package versions so the enum definition and converter agree

Example fix

// before
ConsoleStream stream = default; // 0, unmapped
// after
ConsoleStream stream = ConsoleStream.Stdout;
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is not (ConsoleStream.Stdout or ConsoleStream.Stderr)) throw new InvalidOperationException("ConsoleStream must be Stdout or Stderr before serializing.");

Type guard

bool IsDefinedStream(ConsoleStream s) => s is ConsoleStream.Stdout or ConsoleStream.Stderr;

Try / catch

try { json = JsonSerializer.Serialize(line); }
catch (JsonException ex) when (ex.Message.Contains("Unsupported console stream value"))
{ logger.LogError(ex, "Unmapped ConsoleStream value {Value}", value); }

Prevention

When it happens

Trigger: Serializing a ConsoleStream whose value is not Stdout or Stderr — typically ConsoleStream default(0) if 0 is not a defined member, a cast of an arbitrary int to the enum, or an enum member added by a newer version serialized by an older converter.

Common situations: Initializing ConsoleStream with new ConsoleStream() when zero is undefined; casting raw integers from config or wire data; version skew where a new enum value exists upstream but not in this converter.

Related errors


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

Appendix: source

Thrown at src/modules/Elsa.Diagnostics.ConsoleLogs/Contracts/ConsoleStreamJsonConverter.cs:34

            JsonTokenType.String => ReadString(reader.GetString()),
            JsonTokenType.Number => ReadNumber(ref reader),
            _ => throw new JsonException("The console log stream filter must be 'stdout', 'stderr', or null.")
        };
    }

    public override void Write(Utf8JsonWriter writer, ConsoleStream? value, JsonSerializerOptions options)
    {
        if (value == null)
        {
            writer.WriteNullValue();
            return;
        }

        writer.WriteStringValue(value.Value switch
        {
            ConsoleStream.Stdout => "stdout",
            ConsoleStream.Stderr => "stderr",
            _ => throw new JsonException($"Unsupported console stream value '{value}'.")
        });
    }

    private static ConsoleStream? ReadString(string? value)
    {
        return value?.Trim().ToLowerInvariant() switch
        {
            null or "" or "all" => null,
            "stdout" => ConsoleStream.Stdout,
            "stderr" => ConsoleStream.Stderr,
            _ => throw new JsonException("The console log stream filter must be 'stdout', 'stderr', or null.")
        };
    }

    private static ConsoleStream ReadNumber(ref Utf8JsonReader reader)
    {
        if (!reader.TryGetInt32(out var value) || !Enum.IsDefined(typeof(ConsoleStream), value))
            throw new JsonException("The console log stream filter has an unsupported numeric value.");

View on GitHub (pinned to fe9217bdfa)