abhigyanpatwari/GitNexus · warning

go: files with no resolvable package clause were excluded fr

Error message

go: files with no resolvable package clause were excluded from method-owner resolution (their methods cannot attach to structs declared in sibling files)

What it means

populateGoWorkspaceOwners buckets parsed .go files by directory+package, deriving the package name from file text via inferGoPackageName; files whose package clause cannot be resolved (null) are excluded, so their methods never attach to structs declared in sibling files. The warning reports the skipped count plus a bounded sample (a misrouted vendored tree would otherwise spam one path per file).

Source

Thrown at gitnexus/src/core/ingestion/languages/go/method-owners.ts:66

  // (mirrors the fan-out-cap warning in scope-resolution/pipeline/run.ts).
  let skippedCount = 0;
  const skippedSample: string[] = [];
  for (const parsed of parsedFiles) {
    const pkgName = inferGoPackageName(ctx.fileContents.get(parsed.filePath) ?? '');
    if (pkgName === null) {
      // Count everything, retain only the sample — a misrouted vendored tree
      // would otherwise accumulate one path reference per file to print five.
      skippedCount += 1;
      if (skippedSample.length < SKIPPED_SAMPLE_CAP) skippedSample.push(parsed.filePath);
      continue;
    }
    const key = `${goPackageDir(parsed.filePath)}\0${pkgName}`;
    const bucket = filesByPackage.get(key) ?? [];
    bucket.push(parsed);
    filesByPackage.set(key, bucket);
  }
  if (skippedCount > 0) {
    logger.warn(
      { skippedFiles: skippedCount, sample: skippedSample },
      'go: files with no resolvable package clause were excluded from method-owner ' +
        'resolution (their methods cannot attach to structs declared in sibling files)',
    );
  }

  for (const bucket of filesByPackage.values()) {
    populateGoOwnersInPackage(bucket);
  }
}

function populateGoOwnersInPackage(parsedFiles: readonly ParsedFile[]): void {
  // Build struct name → def map from ALL scopes' ownedDefs (struct defs
  // live in Class scopes now, not Module scope).
  const structByQualifiedName = new Map<string, { nodeId: string; qualifiedName: string }>();
  for (const parsed of parsedFiles) {
    for (const scope of parsed.scopes) {
      for (const def of scope.ownedDefs) {

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Fix or delete the offending .go files — building the module (go build ./...) surfaces exactly which files lack a valid package clause
  2. Exclude testdata/template/vendor directories via ignore rules
  3. If the files are intentional non-source, accept that their methods will not attach to sibling-file structs

Example fix

// before — template.go (not real Go)
// package main   <- commented out
func {{.Method}}() {}

// after — move out of the indexed tree (testdata/template.go)
// or restore a valid clause: package templates
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'node:fs';

// Pre-check: every indexed .go file must have a parseable package clause
function hasGoPackageClause(source: string): boolean {
  // mirrors inferGoPackageName's contract: a non-comment 'package X' line before other declarations
  return /^[ \t]*package[ \t]+\w+/m.test(source.replaceAll(/\/\/.*$/gm, ''));
}
const bad = goFiles.filter((f) => !hasGoPackageClause(readFileSync(f, 'utf8')));
if (bad.length > 0) {
  console.warn('files without a package clause will drop out of method-owner resolution:', bad);
  // fix, move to testdata, or add ignore rules before analyze
}

Type guard

function hasGoPackageClause(source: string): boolean {
  return /^[ \t]*package[ \t]+\w+/m.test(source.replaceAll(/\/\/.*$/gm, ''));
}

Prevention

When it happens

Trigger: A .go file whose package clause is missing or unparseable — truncated files, codegen templates, testdata fixtures, or a vendored tree misrouted into analysis — makes inferGoPackageName return null.

Common situations: testdata/template directories containing non-compiling Go; files with the package line commented out; symptom is Go methods showing no owner struct in the graph.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20). Data as JSON: /api/errors/d6a3bb8e87e88ef8. Report an issue: GitHub.