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

Function printIndexResult

src/bin/codegraph.ts:449–563  ·  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

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