Automattic/harper · error

fileDict path must be a string.

Error message

fileDict path must be a string.

What it means

harper-ls validates the `fileDictPath` field of the LSP initialization/configuration value. If the key is present but its value is not a JSON string (e.g. number, object, boolean), `from_lsp_config` bails with this error instead of proceeding. The check exists because the value is later resolved as a filesystem path.

Source

Thrown at harper-ls/src/config.rs:112

        let Some(Value::Object(value)) = value.get("harper-ls") else {
            bail!("Settings must contain a \"harper-ls\" key.");
        };

        if let Some(v) = value.get("userDictPath") {
            if !v.is_string() {
                bail!("userDict path must be a string.");
            }

            let path = v.as_str().unwrap();
            if !path.is_empty() {
                base.user_dict_path = path.try_resolve_in(workspace_root)?.to_path_buf();
            }
        }

        if let Some(v) = value.get("fileDictPath") {
            if !v.is_string() {
                bail!("fileDict path must be a string.");
            }

            let path = v.as_str().unwrap();
            if !path.is_empty() {
                base.file_dict_path = path.try_resolve_in(workspace_root)?.to_path_buf();
            }
        }

        if let Some(v) = value.get("workspaceDictPath") {
            if !v.is_string() {
                bail!("workspaceDict path must be a string.");
            }
            let path = v.as_str().unwrap();
            if !path.is_empty() {
                base.workspace_dict_path = path.try_resolve_in(workspace_root)?.to_path_buf();
            }
        } else {
            // Resolve the default path in the project root

View on GitHub (pinned to 5fe7d5ab76)

Solutions

  1. Set `fileDictPath` to a string value (e.g. "./file-dict.txt") or remove the key entirely.
  2. Check for `null` sent by the client; some editors serialize disabled settings as null — omit the key instead.
  3. Fix quoting in the settings JSON so the path is a proper JSON string.

Example fix

// before (LSP config JSON)
{ "harper-ls": { "fileDictPath": 42 } }
// after
{ "harper-ls": { "fileDictPath": "./file-dict.txt" } }
Defensive patterns

Strategy: validation

Validate before calling

const cfg = settings['harper-ls'] ?? {};
if ('fileDictPath' in cfg && typeof cfg.fileDictPath !== 'string') {
  throw new TypeError(`fileDictPath must be a string, got ${typeof cfg.fileDictPath}`);
}

Type guard

function isFileDictPathOk(cfg) {
  return !('fileDictPath' in cfg) || typeof cfg.fileDictPath === 'string';
}

Prevention

When it happens

Trigger: Sending a DidChangeConfiguration or initializationOptions payload in which `fileDictPath` is set to a non-string value, e.g. `"fileDictPath": 123`, `true`, `null` inside an object, or a nested config object.

Common situations: Editor settings JSON where a user typed an unquoted path-like number, a settings-sync tool serialized the value as a number/boolean, or a client passed the default `null` inside the config object rather than omitting the key.

Related errors


AI-assisted analysis of Automattic/harper@5fe7d5ab76 (2026-09-06). Data as JSON: /api/errors/b22662c2148bba7e. Report an issue: GitHub.