{"record":{"id":"b54e712d347043bf","repo":"github/copilot-sdk","slug":"expected-a-non-empty-string-token-when-reading-ty","errorCode":null,"errorMessage":"Expected a non-empty string token when reading {typeToConvert.Name}.","messagePattern":"Expected a non-empty string token when reading (.+?)\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Types.cs","lineNumber":31,"sourceCode":"using System.Text.Json.Nodes;\nusing System.Text.Json.Serialization;\nusing System.Threading.Tasks;\n\nnamespace GitHub.Copilot;\n\ninternal static class GeneratedStringEnumJson\n{\n    internal static string ReadValue(ref Utf8JsonReader reader, Type typeToConvert)\n    {\n        if (reader.TokenType != JsonTokenType.String)\n        {\n            throw new JsonException($\"Expected a string token when reading {typeToConvert.Name}, but found {reader.TokenType}.\");\n        }\n\n        var value = reader.GetString();\n        if (string.IsNullOrWhiteSpace(value))\n        {\n            throw new JsonException($\"Expected a non-empty string token when reading {typeToConvert.Name}.\");\n        }\n\n        return value!;\n    }\n\n    internal static void WriteValue(Utf8JsonWriter writer, string value, Type typeToConvert)\n    {\n        if (string.IsNullOrWhiteSpace(value))\n        {\n            throw new JsonException($\"Expected a non-empty string value when writing {typeToConvert.Name}.\");\n        }\n\n        writer.WriteStringValue(value);\n    }\n}\n\n/// <summary>Diagnostic IDs for the Copilot SDK.</summary>\ninternal static class Diagnostics","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Types.cs#L13-L49","documentation":"After confirming the token is a string, GeneratedStringEnumJson.ReadValue reads it and throws this JsonException if the string is null, empty, or whitespace. String-backed enum types require a non-empty value to be meaningful.","triggerScenarios":"Deserializing JSON such as `\"source\": \"\"` or `\"source\": \"   \"` into a type that uses GeneratedStringEnumJson as its converter.","commonSituations":"Server returns empty-string placeholders for unset enum fields; data pipelines that write empty defaults; user-supplied JSON with blank values.","solutions":["Provide a valid non-empty string value in the JSON.","Make the property nullable in the model so empty values can be represented as null instead.","Sanitize/normalize upstream data before deserialization.","Catch JsonException and surface a field-specific validation message."],"exampleFix":"// before\n{\"source\": \"\"}\n// after\n{\"source\": \"user\"}","handlingStrategy":"validation","validationCode":"// reject empty enum strings before deserializing\nvar raw = doc.RootElement.GetProperty(\"source\").GetString();\nif (string.IsNullOrWhiteSpace(raw)) throw new ArgumentException(\"source must be a non-empty string\");","typeGuard":"static bool IsValidEnumString(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { var m = JsonSerializer.Deserialize<Message>(json); }\ncatch (JsonException ex) { throw new InvalidDataException(\"empty string enum value in payload\", ex); }","preventionTips":["Treat empty strings as null for optional enum fields","Sanitize upstream data before deserialization","Make enum properties nullable to represent absence","Add schema validation rejecting empty strings"],"tags":["json","deserialization","dotnet","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}