{"record":{"id":"cff9a0d768976d96","repo":"elsa-workflows/elsa-core","slug":"a-metadata-key-is-required","errorCode":null,"errorMessage":"A metadata key is required.","messagePattern":"A metadata key is required\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogContextAccessor.cs","lineNumber":33,"sourceCode":"\n    private ConsoleLogContextAccessor()\n    {\n    }\n\n    /// <inheritdoc />\n    public IReadOnlyDictionary<string, string> GetMetadata()\n    {\n        var metadata = CurrentFrame.Value?.Metadata;\n        return metadata == null || metadata.Count == 0\n            ? Empty\n            : new Dictionary<string, string>(metadata, StringComparer.OrdinalIgnoreCase);\n    }\n\n    /// <inheritdoc />\n    public IDisposable PushMetadata(string key, string value)\n    {\n        if (string.IsNullOrWhiteSpace(key))\n            throw new ArgumentException(\"A metadata key is required.\", nameof(key));\n\n        if (string.IsNullOrWhiteSpace(value))\n            throw new ArgumentException(\"A metadata value is required.\", nameof(value));\n\n        var previous = CurrentFrame.Value;\n        var metadata = previous?.Metadata != null\n            ? new Dictionary<string, string>(previous.Metadata, StringComparer.OrdinalIgnoreCase)\n            : new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);\n\n        metadata[key] = value;\n        CurrentFrame.Value = new(metadata);\n        return new MetadataScope(previous);\n    }\n\n    /// <inheritdoc />\n    public IDisposable PushWorkflowInstanceId(string workflowInstanceId) =>\n        PushMetadata(ConsoleLogMetadataKeys.WorkflowInstanceId, workflowInstanceId);\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogContextAccessor.cs#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\naccessor.PushMetadata(config.MetadataKey!, instanceId); // MetadataKey may be empty\n// after\nif (!string.IsNullOrWhiteSpace(config.MetadataKey))\n    accessor.PushMetadata(config.MetadataKey, instanceId);","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value))\n    accessor.PushMetadata(key, value);","typeGuard":"bool CanPushMetadata(string? k, string? v) => !string.IsNullOrWhiteSpace(k) && !string.IsNullOrWhiteSpace(v);","tryCatchPattern":"try { accessor.PushMetadata(key, value); }\ncatch (ArgumentException ex) when (ex.ParamName is \"key\" or \"value\")\n{ logger.LogWarning(ex, \"Skipped empty console log metadata\"); }","preventionTips":["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"],"tags":["argument-validation","console-logs","logging"],"backgroundTag":"empty-required-field","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}