MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / printIndexResult

Function printIndexResult

src/bin/codegraph.ts:468–582  ·  view source on GitHub ↗

* Print indexing results using clack log methods

(clack: typeof import('@clack/prompts'), result: IndexResult, projectPath?: string)

Source from the content-addressed store, hash-verified

466 * Print indexing results using clack log methods
467 */
468function printIndexResult(clack: typeof import('@clack/prompts'), result: IndexResult, projectPath?: string): void {
469 const hasErrors = result.filesErrored > 0;
470 const parseWarnings = result.errors.filter((e) => e.code === 'parse_error' && e.severity === 'warning');
471
472 // Surface non-file-level failures (e.g. lock-acquisition failure
473 // when another indexer is running) before the file-count branches.
474 // Without this the CLI falls through to "No files found to index",
475 // which is actively misleading — the index DID run, it just couldn't
476 // get the lock.
477 //
478 // If success is false but no severity:'error' entry exists in
479 // `result.errors` (degenerate case — shouldn't happen in practice
480 // but worth guarding because the result shape is plumbed through
481 // multiple call sites), fall back to a generic message rather than
482 // continuing to the misleading "No files found" branch or throwing.
483 if (!result.success && !hasErrors && result.filesIndexed === 0) {
484 const generic = result.errors.find((e) => e.severity === 'error');
485 clack.log.error(generic?.message ?? `Indexing failed ${getGlyphs().dash} no further details available`);
486 return;
487 }
488
489 if (result.filesIndexed > 0) {
490 if (hasErrors) {
491 clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files (${formatNumber(result.filesErrored)} could not be parsed)`);
492 } else {
493 clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files`);
494 }
495 clack.log.info(`${formatNumber(result.nodesCreated)} nodes, ${formatNumber(result.edgesCreated)} edges in ${formatDuration(result.durationMs)}`);
496 // Warning-only parse failures keep indexing successful, but must be visible.
497 for (const warning of parseWarnings) {
498 clack.log.warn(warning.message);
499 }
500 // A PARTIAL index (files silently dropped mid-pipeline) must not pass
501 // as a clean run — it's the difference between "indexed the repo" and
502 // "indexed most of the repo, quietly". Only the completeness
503 // reconciliation warning; per-file extractor warnings stay in the
504 // error-code summary below.
505 for (const w of result.errors.filter((e) => e.code === 'index_partial')) {
506 clack.log.warn(w.message);
507 }
508 // Files salvaged from comment-stripped source after repeated parser
509 // failures are indexed but possibly incomplete — say so here, or the run
510 // reads as fully clean and the index quietly disagrees with a later
511 // re-parse of the same bytes (#1565).
512 const salvaged = result.errors.filter((e) => e.code === 'salvaged_stripped');
513 if (salvaged.length > 0) {
514 const sample = salvaged.slice(0, 3).map((e) => e.filePath).filter(Boolean).join(', ');
515 const more = salvaged.length > 3 ? ', ...' : '';
516 clack.log.warn(`${formatNumber(salvaged.length)} file(s) indexed from comment-stripped source after repeated parse failures ${getGlyphs().dash} symbols may be incomplete (${sample}${more})`);
517 }
518 } else if (hasErrors) {
519 clack.log.error(`Indexing failed ${getGlyphs().dash} all ${formatNumber(result.filesErrored)} files had errors`);
520 } else if (result.filesSkippedUnsupported) {
521 // A project CodeGraph has no grammar for used to be indistinguishable from
522 // an empty one: same message, same `complete` state, same exit 0. Say which
523 // files were there and that the graph is empty on purpose, so nobody — and
524 // no agent trusting the graph — reads silence as "this code doesn't exist"
525 // (#1502).

Callers 3

offerIndexIgnoredReposFunction · 0.85
runInitFunction · 0.85
mainFunction · 0.85

Calls 13

getGlyphsFunction · 0.90
getCodeGraphDirFunction · 0.90
formatDurationFunction · 0.85
writeErrorLogFunction · 0.85
infoMethod · 0.80
warnMethod · 0.80
mapMethod · 0.80
fromMethod · 0.80
formatNumberFunction · 0.70
errorMethod · 0.65
getMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected