neoclide/coc.nvim · error · Error
Illegal argument: base
Error message
Illegal argument: base
What it means
The RelativePattern constructor validates its base argument: it must be a plain string path, a URI instance, or an object with a string .uri property (a WorkspaceFolder). Anything else (null, undefined, a plain object without uri) triggers illegalArgument('base'), reported as "Illegal argument: base".
Source
Thrown at src/model/relativePattern.ts:13
'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,View on GitHub (pinned to 50e974d969)
Solutions
- Pass a string path, a proper URI (workspace.createFileRangeUri/Uri.file), or a real WorkspaceFolder.
- Guard base for null/undefined before constructing the pattern.
- Ensure the object's .uri is a string; convert URI objects to strings with .toString() if needed.
- Avoid mixing Uri implementations from different module copies.
Example fix
// before
const rp = new RelativePattern(maybeFolder, '**/*.ts')
// after
if (maybeFolder && (typeof maybeFolder === 'string' || typeof maybeFolder.uri === 'string')) {
const rp = new RelativePattern(maybeFolder, '**/*.ts')
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!(typeof base === 'string' || (base && typeof base.uri === 'string'))) throw new Error('RelativePattern base must be a string or folder-like') Type guard
function isRelativePatternBase(v: unknown): v is string | { uri: string } {
return typeof v === 'string' || (!!v && typeof (v as any).uri === 'string')
} Try / catch
try { const rp = new RelativePattern(base, glob) } catch (e) { if (String(e).includes('Illegal argument: base')) { /* normalize base to Uri.file(...) and retry */ } else throw e } Prevention
- Always construct base with Uri.file(path) or take it from workspace APIs
- Guard nullable workspace folder variables
- Avoid mixing Uri classes from duplicate coc.nvim module copies
When it happens
Trigger: new RelativePattern(undefined, '**/*.ts'), passing a WorkspaceFolder-like object whose uri is not a string, or passing a null base.
Common situations: Destructuring a workspace folder before it is assigned; using a vscode.Uri from a different coc/vscode module instance so URI.isUri fails and the .uri fallback also misses; copying code from VS Code API where base types differ.
Related errors
AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31).
Data as JSON: /api/errors/56e33760b39d06f7.
Report an issue: GitHub.