Automattic/harper · error

excludePatterns must be an array.

Error message

excludePatterns must be an array.

What it means

When `excludePatterns` is present in the LSP config, `from_lsp_config` requires it to be a JSON array of glob strings; the array is fed into a GlobSet builder used to skip documents. Non-array values (string, null, object) bail with this error before any glob compilation.

Source

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

                base.isolate_english = *v;
            } else {
                bail!("isolateEnglish path must be a boolean.");
            }
        }

        if let Some(v) = value.get("maxFileLength") {
            base.max_file_length = serde_json::from_value(v.clone())?;
        }

        if let Some(v) = value.get("markdown")
            && let Some(v) = v.get("IgnoreLinkTitle")
        {
            base.markdown_options.ignore_link_title = serde_json::from_value(v.clone())?;
        }

        if let Some(v) = value.get("excludePatterns") {
            let Some(a) = v.as_array() else {
                bail!("excludePatterns must be an array.");
            };

            let patterns: Vec<Value> = a.to_vec();
            if !patterns.is_empty() {
                let mut builder = GlobSet::builder();

                for pattern in patterns {
                    builder.add(Glob::new(pattern.as_str().unwrap())?);
                }

                base.exclude_patterns = builder.build()?;
            }
        }

        Ok(base)
    }
}

View on GitHub (pinned to 5fe7d5ab76)

Solutions

  1. Wrap the pattern(s) in a JSON array: ["pattern1", "pattern2"].
  2. Remove the key if no exclusions are needed (empty arrays are accepted).
  3. Ensure each array element is a string glob; element type errors surface later during glob compilation.

Example fix

// before
{ "excludePatterns": "**/node_modules/**" }
// after
{ "excludePatterns": ["**/node_modules/**"] }
Defensive patterns

Strategy: validation

Validate before calling

if ('excludePatterns' in cfg) {
  const v = cfg.excludePatterns;
  if (!Array.isArray(v) || v.some(p => typeof p !== 'string')) {
    throw new TypeError('excludePatterns must be an array of glob strings');
  }
}

Type guard

function isExcludePatternsOk(cfg) {
  const v = cfg.excludePatterns;
  return !('excludePatterns' in cfg) || (Array.isArray(v) && v.every(p => typeof p === 'string'));
}

Prevention

When it happens

Trigger: Sending `excludePatterns` as a single string instead of an array, as null, or as an object, e.g. `{ "excludePatterns": "**/node_modules/**" }`.

Common situations: Users with one exclusion pattern forgetting the array brackets; config migrations from boolean/string-based settings; editors serializing a single-value setting as a scalar.

Related errors


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