neoclide/coc.nvim · error · Error
Illegal argument: pattern
Error message
Illegal argument: pattern
What it means
RelativePattern requires the pattern argument to be a string glob; passing any other type throws illegalArgument('pattern') with message "Illegal argument: pattern". This check runs after base validation in the constructor.
Source
Thrown at src/model/relativePattern.ts:17
'use strict'
import { URI } from 'vscode-uri'
import { illegalArgument } from '../util/errors'
import { WorkspaceFolder } from 'vscode-languageserver-types'
export default class RelativePattern {
public pattern: string
public baseUri: URI
constructor(base: WorkspaceFolder | URI | string, pattern: string) {
if (typeof base !== 'string') {
if (!base || !URI.isUri(base) && typeof base.uri !== 'string') {
throw illegalArgument('base')
}
}
if (typeof pattern !== 'string') {
throw illegalArgument('pattern')
}
if (typeof base === 'string') {
this.baseUri = URI.file(base)
} else if (URI.isUri(base)) {
this.baseUri = base
} else {
this.baseUri = URI.parse(base.uri)
}
this.pattern = pattern
}
public toJSON() {
return {
pattern: this.pattern,
baseUri: this.baseUri.toJSON()
}
}
}View on GitHub (pinned to 50e974d969)
Solutions
- Pass a glob string such as '**/*.ts'.
- Coalesce config values with a default: pattern ?? '**/*'.
- Convert RegExp or array inputs to a string (join array patterns with commas or build multiple RelativePatterns).
- Validate typeof pattern === 'string' before constructing.
Example fix
// before
new RelativePattern(folder, config.exclude) // array | undefined
// after
new RelativePattern(folder, Array.isArray(config.exclude) ? config.exclude.join(',') : (config.exclude ?? '**/*')) Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof pattern !== 'string') throw new Error('RelativePattern pattern must be a glob string') Type guard
function isGlob(v: unknown): v is string { return typeof v === 'string' } Try / catch
try { const rp = new RelativePattern(base, pattern) } catch (e) { if (String(e).includes('Illegal argument: pattern')) { const rp = new RelativePattern(base, String(pattern ?? '**/*')) } else throw e } Prevention
- Coalesce config glob values with defaults (pattern ?? '**/*')
- Join array globs into one string or create multiple RelativePatterns
- Use globs, not RegExp, for watcher patterns
When it happens
Trigger: new RelativePattern(base, someVar) where someVar is undefined, null, a RegExp, or an array of globs.
Common situations: Reading the glob from config where the key is missing (undefined); passing a RegExp instead of a glob string; arrays of patterns from settings not being joined into one string.
Related errors
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/2bf557a873fa8d04.
Report an issue: GitHub.