{"record":{"id":"b677d8ecf1bfccdb","repo":"apple/pkl","slug":"invalidglobtoocomplex","errorCode":"invalidGlobTooComplex","errorMessage":"invalidGlobTooComplex","messagePattern":"invalidGlobTooComplex","errorType":"error_code","errorClass":"InvalidGlobPatternException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java","lineNumber":340,"sourceCode":"  }\n\n  private static void doExpandHierarchicalGlobPart(\n      SecurityManager securityManager,\n      ReaderBase reader,\n      String expandedGlobSoFar,\n      Pattern globPartPattern,\n      URI baseUri,\n      boolean isGlobStar,\n      boolean hasAbsoluteGlob,\n      MutableLong listElementCallCount,\n      List<ResolvedGlobElement> result)\n      throws IOException,\n          SecurityManagerException,\n          InvalidGlobPatternException,\n          ExternalReaderProcessException {\n\n    if (listElementCallCount.getAndIncrement() > maxListElements()) {\n      throw new InvalidGlobPatternException(ErrorMessages.create(\"invalidGlobTooComplex\"));\n    }\n    var elements = reader.listElements(securityManager, baseUri);\n    for (var element : sorted(elements)) {\n      var elementPath = resolvePath(expandedGlobSoFar, element.getName(), hasAbsoluteGlob);\n      if (globPartPattern.matcher(element.getName()).matches()) {\n        var name = element.isDirectory() ? element.getName() + \"/\" : element.getName();\n        var elementUri = IoUtils.resolve(reader, baseUri, name);\n        result.add(new ResolvedGlobElement(elementPath, elementUri, element.isDirectory()));\n      }\n      if (element.isDirectory() && isGlobStar) {\n        var elementUri = IoUtils.resolve(reader, baseUri, element.getName() + \"/\");\n        var newExpandedGlobPattern =\n            resolvePath(expandedGlobSoFar, element.getName(), hasAbsoluteGlob);\n        doExpandHierarchicalGlobPart(\n            securityManager,\n            reader,\n            newExpandedGlobPattern,\n            globPartPattern,","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java#L322-L358","documentation":"Hierarchical glob expansion enumerates directories recursively and, to protect against pathological patterns and huge trees, counts list-element expansions against a limit (maxListElements). Exceeding it aborts with invalidGlobTooComplex, signaling the glob would traverse too many directory listings rather than a syntax problem.","triggerScenarios":"Expanding a hierarchical glob (e.g. `**` over a very deep/wide tree, or a pattern matching many nested directories) where the number of directory-list element visits exceeds the configured maxListElements budget in doExpandHierarchicalGlobPart.","commonSituations":"Running globs against enormous directories (node_modules, build outputs, monorepo roots), overly broad patterns like \"**/*\" at a filesystem root, or globbing remote/package readers with many elements.","solutions":["Narrow the glob's base path so expansion starts deeper in the tree (e.g. \"src/**/*.pkl\" instead of \"**/*.pkl\")","Replace `**` with fixed intermediate segments where the layout is known","Exclude/generated-code-heavy directories from the glob base (e.g. point at the package dir, not the repo root)"],"exampleFix":"// before\nglob(\"**/*.pkl\")\n// after\nglob(\"src/**/*.pkl\")","handlingStrategy":"try-catch","validationCode":"// estimate breadth: cap leading ** segments and known huge dirs\nconst tooBroad = (glob, base) => glob.startsWith('**') && (base === '/' || base === '');","typeGuard":null,"tryCatchPattern":"try {\n  var files = GlobResolver.expandHierarchicalGlob(...);\n} catch (InvalidGlobPatternException e) {\n  if (e.getMessage().contains(\"TooComplex\")) {\n    // narrow the base path or reduce ** and retry\n  } else throw e;\n}","preventionTips":["Anchor globs at the deepest reasonable directory","Avoid bare ** or **/* over repo roots and dependency dirs (node_modules, target)","Increase maxListElements only deliberately; prefer narrower patterns"],"tags":["glob","performance","recursion-limit","pkl"],"backgroundTag":"glob-pattern-too-complex","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}