apple/pkl · error · VmException

invalidGlobPattern

invalidGlobPattern

Error message

Invalid glob pattern `{0}`.

What it means

Pkl throws this when the glob pattern in a glob import is not a valid glob expression. GlobResolver raises InvalidGlobPatternException (e.g. unbalanced brackets, invalid escape sequences) and Pkl reports the offending pattern with the exception message as a hint.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ImportGlobNode.java:107

              currentModule.getUri(),
              globPattern);
      var builder = new VmObjectBuilder(resolvedElements.size());
      for (var entry : resolvedElements.entrySet()) {
        builder.addEntry(entry.getKey(), getMemberNode());
      }
      cachedResult = builder.toMapping(resolvedElements);
      return cachedResult;
    } catch (IOException e) {
      throw exceptionBuilder().evalError("ioErrorResolvingGlob", importUri).withCause(e).build();
    } catch (SecurityManagerException | HttpClientException e) {
      throw exceptionBuilder().withCause(e).build();
    } catch (PackageLoadError e) {
      throw exceptionBuilder().adhocEvalError(e.getMessage()).build();
    } catch (InvalidGlobPatternException e) {
      throw exceptionBuilder()
          .evalError("invalidGlobPattern", globPattern)
          .withHint(e.getMessage())
          .build();
    } catch (ExternalReaderProcessException e) {
      throw exceptionBuilder().evalError("externalReaderFailure").withCause(e).build();
    }
  }
}

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Read the hint for the exact syntax problem and fix the pattern (close brackets, remove bad escapes).
  2. Use only supported glob syntax: `*`, `**`, `?`, and character classes like [a-z].
  3. Test the pattern against expected file names incrementally.
  4. If migrating from another glob dialect, rewrite the pattern in Pkl's glob syntax.

Example fix

// before
import "src/**[[a-z].pkl" as mods*
// after
import "src/**/[a-z]*.pkl" as mods*
Defensive patterns

Strategy: validation

Validate before calling

// Validate the glob pattern before writing it into an import:
//   balanced [ ] pairs, no trailing backslash, only * ** ? [a-z] constructs
// e.g. host-side: pattern.matches("[^\\[\\]]*(\\[[^\\]]*\\])?[^\\[\\]]*")

Prevention

When it happens

Trigger: Writing `import "**[.pkl" as x*` or any pattern with malformed syntax: unmatched `[`/`]`, trailing backslash, unsupported wildcard combinations.

Common situations: Hand-editing glob patterns and leaving an unclosed character class; copying patterns from tools with different glob dialects (e.g. Windows or npm-style globs with unsupported syntax).

Related errors


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