apple/pkl · error · InvalidGlobPatternException
invalidGlobInvalidTerminatingCharacter
invalidGlobInvalidTerminatingCharacter
Error message
invalidGlobInvalidTerminatingCharacter
What it means
A backslash in a glob must escape one of the special characters `?`, `*`, `[`, `{`, or `\`. If a trailing `\` has no following character (getNextChar returns NULL), toRegexString throws InvalidGlobPatternException with this code indicating an invalid terminating character.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java:185
case '}' -> {
if (inGroup) {
inGroup = false;
sb.append("))");
} else {
sb.append('}');
}
}
case ',' -> {
if (inGroup) {
sb.append(")|(?:");
} else {
sb.append(',');
}
}
case '\\' -> {
var next = getNextChar(globPattern, i);
if (next == NULL) {
throw new InvalidGlobPatternException(
ErrorMessages.create("invalidGlobInvalidTerminatingCharacter"));
}
if (next != '?' && next != '*' && next != '[' && next != '{' && next != '\\') {
throw new InvalidGlobPatternException(
ErrorMessages.create("invalidGlobInvalidEscapeCharacter", next));
}
sb.append('\\').append(next);
i++;
}
case '[' -> i = consumeCharacterClass(globPattern, i, sb);
case '?' -> {
var next = getNextChar(globPattern, i);
if (next == '(') {
throw new InvalidGlobPatternException(ErrorMessages.create("invalidGlobExtGlob"));
}
sb.append(".");
}
case '*' -> {View on GitHub (pinned to f3efcbfc9b)
Solutions
- Remove the trailing backslash from the pattern.
- If escaping a literal special character, ensure a valid escapable character (`? * [ { \\`) follows the backslash.
- Fix quoting/escaping in the config source so the intended number of backslashes reaches the resolver.
Example fix
// before glob = "src\\" // after glob = "src/**"
Defensive patterns
Strategy: validation
Validate before calling
if (glob.endsWith("\\")) throw new IllegalArgumentException("Glob must not end with a bare backslash: " + glob);
Try / catch
try { return GlobResolver.toRegexPattern(glob); } catch (InvalidGlobPatternException e) { throw new IllegalArgumentException("Invalid escape in glob: " + glob, e); }
Prevention
- Never end globs with a backslash.
- Double-check backslash escaping through config files/shells.
- Prefer forward slashes in glob patterns.
When it happens
Trigger: Passing a glob ending in a bare backslash (e.g. `src\\` on a path or in JSON/YAML where `\\` collapsed to a single `\\`) to GlobResolver.toRegexString/toRegexPattern.
Common situations: Windows-style paths pasted into glob patterns; config files or shell quoting eating one level of backslashes; intending a literal trailing backslash in a directory name.
Related errors
- invalidGlobPattern
- invalidGlobMissingCharacterClassTerminator
- invalidGlobUnsupportedFeature
- invalidGlobInvalidCharacterInCharacterClass
- invalidGlobNestedSubpattern
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/1b385e7c39136a08.
Report an issue: GitHub.