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

  1. Remove the trailing backslash from the pattern.
  2. If escaping a literal special character, ensure a valid escapable character (`? * [ { \\`) follows the backslash.
  3. 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

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


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/1b385e7c39136a08. Report an issue: GitHub.