Flow-Launcher/Flow.Launcher · error · ArgumentException

DoublePinyinSchema '{schemaKey}' is invalid or double pinyin

Error message

DoublePinyinSchema '{schemaKey}' is invalid or double pinyin table is broken.

What it means

Thrown as ArgumentException when the deserialized table is a valid non-null Dictionary but does not contain a key matching _settings.DoublePinyinSchema.ToString(). The schema name (an enum value, e.g. a custom schema) must exist as a top-level key in double_pinyin.json or the table cannot be selected. Like error 10, this propagates uncaught from CreateDoublePinyinTableFromStream.

Source

Thrown at Flow.Launcher.Infrastructure/PinyinAlphabet.cs:61

                }
            };
        }

        public void Reload()
        {
            LoadDoublePinyinTable();
            _pinyinCache.Clear();
        }

        private void CreateDoublePinyinTableFromStream(Stream jsonStream)
        {
            var table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonStream) ??
                throw new InvalidOperationException("Failed to deserialize double pinyin table: result is null");

            var schemaKey = _settings.DoublePinyinSchema.ToString();
            if (!table.TryGetValue(schemaKey, out var schemaDict))
            {
                throw new ArgumentException($"DoublePinyinSchema '{schemaKey}' is invalid or double pinyin table is broken.");
            }

            currentDoublePinyinTable = new ReadOnlyDictionary<string, string>(schemaDict);
        }

        private void LoadDoublePinyinTable()
        {
            if (!_settings.UseDoublePinyin)
            {
                currentDoublePinyinTable = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>());
                return;
            }

            var tablePath = Path.Combine(AppContext.BaseDirectory, "Resources", "double_pinyin.json");
            try
            {
                using var fs = File.OpenRead(tablePath);
                CreateDoublePinyinTableFromStream(fs);

View on GitHub (pinned to 7fc63b07bb)

Solutions

  1. Open Resources/double_pinyin.json and confirm there is a top-level key whose name matches the selected DoublePinyinSchema enum value's ToString().
  2. Reset the DoublePinyinSchema setting to a known-supported schema (e.g. the default).
  3. If you added a custom enum value, add a matching schema section to the JSON file.
  4. Restore the resource file from the official install to rule out manual edits.

Example fix

// before — hard fail on unknown schema
if (!table.TryGetValue(schemaKey, out var schemaDict))
    throw new ArgumentException($"DoublePinyinSchema '{schemaKey}' is invalid...");

// after — fall back to first available schema and log
if (!table.TryGetValue(schemaKey, out var schemaDict))
{
    Log.Warn(nameof(PinyinAlphabet), $"Schema '{schemaKey}' not found; falling back");
    schemaDict = table.Values.FirstOrDefault() ?? new Dictionary<string,string>();
}
Defensive patterns

Strategy: validation

Validate before calling

var schemaKey = _settings.DoublePinyinSchema.ToString();
using var fs = File.OpenRead(tablePath);
var table = JsonSerializer.Deserialize<Dictionary<string,Dictionary<string,string>>>(fs);
if (table is null || !table.ContainsKey(schemaKey))
{ Log.Warn(...); currentDoublePinyinTable = Empty; return; }

Type guard

null

Try / catch

try { CreateDoublePinyinTableFromStream(fs); }
catch (ArgumentException ex) when (ex.Message.Contains("DoublePinyinSchema"))
{ Log.Exception(...); currentDoublePinyinTable = Empty; }

Prevention

When it happens

Trigger: User selected a DoublePinyinSchema enum value whose string name is not present as a key in double_pinyin.json; the enum was extended with a new schema but the resource file wasn't updated; the schema's ToString() casing doesn't match the JSON key; the table JSON was edited and a schema section deleted.

Common situations: Version skew: a newer build references a schema enum not in the shipped resource; user manually edited double_pinyin.json and removed a schema; a plugin/extension added a schema enum without providing its key mapping; enum renamed but JSON not migrated.

Related errors


AI-assisted analysis of Flow-Launcher/Flow.Launcher@7fc63b07bb (2026-08-13). Data as JSON: /api/errors/a01927fceac8ccea. Report an issue: GitHub.