Skip to content

AST extraction crashes with 'IndexError: tuple index out of range' on pnpm-workspace.yaml with 'packages: - .' (Python 3.10) #1083

Closed

Description

@santiagotorres-united

Summary

graphify update . crashes during AST extraction on every .ts/.tsx/.js file with IndexError: tuple index out of range when the project's pnpm-workspace.yaml lists the repo root as a package (packages: - '.'). This is valid pnpm config (single-package-at-root workspace), but it produces a Path.glob('.') call, which raises IndexError on Python 3.10.

Result: 0 nodes extracted, build aborts with Rebuild failed: tuple index out of range. The failure is uniform across all files, so it looks like a parser/tree-sitter problem — but it isn't.

Environment

  • graphify (graphifyy) 0.8.25
  • Python 3.10.18
  • Platform: macOS 15.7.4 (arm64)

Repro

  1. In any JS/TS project, create a pnpm-workspace.yaml:
    packages:
      - '.'
      - 'examples/*'
  2. Have at least one .ts file with an import statement (triggers the workspace resolver).
  3. Run graphify update .

Every file is skipped:

warning: skipped /…/src/nav/appCatalog.ts (IndexError: tuple index out of range)
…
Nothing to update or rebuild failed — check output above.
[graphify watch] Rebuild failed: tuple index out of range

Root cause

The traceback (normally swallowed by the broad except in extract_js):

File ".../graphify/extract.py", line 2229, in walk
    config.import_handler(node, source, file_nid, stem, edges, str_path)
File ".../graphify/extract.py", line 1238, in _import_js
    resolved = _resolve_js_import_target(raw, str_path)
File ".../graphify/extract.py", line 1213, in _resolve_js_import_target
    resolved_path = _resolve_js_module_path(raw, Path(str_path).parent)
File ".../graphify/extract.py", line 396, in _resolve_js_module_path
    return _resolve_workspace_import(raw, start_dir)
File ".../graphify/extract.py", line 360, in _resolve_workspace_import
    packages = _load_workspace_packages(start_dir)
File ".../graphify/extract.py", line 310, in _load_workspace_packages
    for package_dir in root.glob(pattern):
File ".../python3.10/pathlib.py", line 1033, in glob
    selector = _make_selector(tuple(pattern_parts), self._flavour)
File ".../python3.10/pathlib.py", line 369, in _make_selector
    pat = pattern_parts[0]
IndexError: tuple index out of range

_workspace_globs correctly returns '.' as a package glob, but _load_workspace_packages then calls root.glob('.'). On Python 3.10, Path.glob('.') has empty pattern_parts and raises IndexError (Python 3.11+ raises a clearer error / behaves differently, but . is never a meaningful glob — it just means "this directory").

Suggested fix

In _load_workspace_packages (extract.py ~line 309), treat ././ as the workspace root itself instead of globbing:

packages: dict[str, Path] = {}
for pattern in _workspace_globs(root / "pnpm-workspace.yaml"):
    package_dirs = [root] if pattern in (".", "./") else root.glob(pattern)
    for package_dir in package_dirs:
        ...

This resolves the root package correctly and avoids the empty-glob crash. Verified locally against 0.8.25 — full extraction (276 files, 1692 nodes) succeeds with this one-line guard.

(Possible secondary hardening: extract_js swallows the real traceback and only surfaces IndexError: tuple index out of range, which made this look like a tree-sitter grammar/version issue. Logging the failing frame, or at least the resolver context, at a higher verbosity would shorten diagnosis.)

Activity

  1. safishamsi commented on May 30, 2026

    @safishamsi
    Member

    Fixed in commit d4e1d4b.

    Root cause confirmed: _load_workspace_packages (extract.py:310) called root.glob('.') when pnpm-workspace.yaml has packages: - '.'. On Python 3.10, Path.glob('.') hits empty pattern_parts and raises IndexError — which then propagated through every JS/TS import resolution, causing every file to be skipped uniformly.

    Your one-line guard was exactly right:

    package_dirs: list[Path] = [root] if pattern in (".", "./") else list(root.glob(pattern))

    Also added GRAPHIFY_DEBUG=1 env var support in _safe_extract so future crashes print the full traceback rather than just the exception message — good call on flagging that diagnostic gap. Plus a regression test for this exact case. Thanks for the precise repro and proposed fix.

  2. added a commit that references this issue on May 30, 2026
    d4e1d4b
  3. added a commit that references this issue on Aug 13, 2026
    37b01e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions