// What a command's result means for the window: exit 1 of scan / check / validate / health with the --json result // printed is "found problems" (shown as the findings), 3 is "declined"; only a real failure is an error, and then in // the command's own words (its error line, Google errors as one plain line), never a bare "Exit code N". import { errorLine, type Outcome, outcomeOf, type ToolResult } from '../../../../cli/lib/desktop-protocol'; import { plainError } from '../../../../cli/lib/google-errors'; import { t } from '../i18n'; export function outcome(method: string, r: Pick): Outcome { return r.outcome ?? outcomeOf(method, r.exitCode, r.data !== undefined); } /** The result carries data the screen can show (ok, or findings). */ export const usable = (method: string, r: Pick): boolean => r.data !== undefined && ['ok', 'findings'].includes(outcome(method, r)); /** A failed run in words: the command's error line (Google JSON bodies as one plain line). */ export function failureText(r: Pick): string { const line = r.error || errorLine('', r.output ?? ''); return line ? plainError(line) : t('common.exitNoMessage', { code: r.exitCode }); }