apple/pkl · error · VmException

invalidGlobPattern

invalidGlobPattern

Error message

invalidGlobPattern

What it means

A glob import (e.g. import("*.pkl")) used a pattern that is invalid. The module resolver threw InvalidGlobPatternException, converted into invalidGlobPattern with the offending pattern and its source section.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java:127

                  theModuleKey,
                  moduleKey,
                  moduleKey.getUri(),
                  entry.stringValue());
          for (var globElement : elements.values()) {
            var moduleUri = globElement.uri();
            var mk = moduleResolver.resolve(moduleUri);
            var rmk = mk.resolve(securityManager);
            result.add(new ImportEntry(moduleUri, rmk));
          }
        } else {
          var resolvedUri =
              IoUtils.resolve(securityManager, moduleKey, IoUtils.toUri(entry.stringValue()));
          var mKey = moduleResolver.resolve(resolvedUri);
          var rmk = mKey.resolve(securityManager);
          result.add(new ImportEntry(resolvedUri, rmk));
        }
      } catch (InvalidGlobPatternException e) {
        throw new VmExceptionBuilder()
            .evalError("invalidGlobPattern", entry.stringValue())
            .withSourceSection(entry.sourceSection())
            .build();
      } catch (FileNotFoundException | NoSuchFileException e) {
        throw new VmExceptionBuilder()
            .evalError("cannotFindModule", entry.stringValue())
            .withSourceSection(entry.sourceSection())
            .build();
      } catch (URISyntaxException e) {
        throw new VmExceptionBuilder()
            .evalError("invalidModuleUri", entry.stringValue())
            .withHint(e.getReason())
            .withSourceSection(entry.sourceSection())
            .build();
      } catch (IOException e) {
        throw new VmExceptionBuilder()
            .evalError("ioErrorLoadingModule", entry.stringValue())
            .withCause(e)

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Correct the glob pattern at the reported source section (use valid globs like 'dir/*.pkl' or 'dir/**/*.pkl')
  2. Avoid characters with special meaning unless intended; escape literals
  3. If dynamic, validate the pattern before interpolating it into the import

Example fix

// before
import("src/**foo*.pkl")
// after
import("src/**/*.pkl")
Defensive patterns

Strategy: validation

Validate before calling

function validateGlob(p) { if (!p || /\*\*[^\/]/.test(p)) throw new Error('invalid glob pattern: ' + p) }

Type guard

const isValidGlob = (p) => typeof p === 'string' && p.length > 0 && !/\*\*[^\/]/.test(p);

Prevention

When it happens

Trigger: import() of a glob URI whose pattern violates glob rules (e.g. 'a**b' misuse, empty pattern, invalid special characters) during collectImports.

Common situations: Hand-written glob with misplaced '**'; escaping mistakes on Windows paths; patterns built programmatically that end up malformed.

Related errors


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