openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
31 lines (30 loc) • 2.15 kB
JavaScript
import { n as containsAsciiControlCharacter } from "./string-normalization-DLmfYZXI.mjs";
import { s as redactSensitiveText } from "./redact-Mj7pppxC.mjs";
import { s as parseRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs";
import { t as normalizeSupportDiagnosticErrorCode } from "./diagnostic-support-redaction-CA1pCV-N.mjs";
import { validRange } from "semver";
//#region src/infra/npm-error.ts
/** Shared npm error classification for install, metadata, and permission failures. */
function parseNpmErrorCode(e) {
const t = /\bnpm (?:ERR!|error) code ([A-Z][A-Z0-9_]+)/u.exec(e)?.[1];
if (t) return t;
if (/No version matching "[^"\n]+" found for specifier "[^"\n]+" \(but package exists\)/u.test(e)) return "ETARGET";
if (/Integrity check failed for tarball:/u.test(e)) return "EINTEGRITY";
if (/404 - GET |GET \S+ - 404\b/u.test(e)) return "E404";
return e.match(/\b[A-Z][A-Z0-9_]+\b/gu)?.map(normalizeSupportDiagnosticErrorCode).find(Boolean) ?? (/is not in this registry/iu.test(e) ? "E404" : void 0);
}
/** Admit registry specs only; diagnostic URLs, local paths, and shell text stay private. */
function npmFailurePackageSpec(e) {
const t = /No version matching "([^"\n]+)" found for specifier "([^"\n]+)" \(but package exists\)/u.exec(e);
const n = (t ? `${t[2]}@${t[1]}` : void 0) ?? /No matching version found for (.+)\.(?:\r?$)/mu.exec(e)?.[1] ?? /(?:404\s+|The requested resource )['"]([^'"]+)['"]/u.exec(e)?.[1] ?? /(?:tarball|cached) data for (\S+) \(/u.exec(e)?.[1] ?? /Integrity check failed for tarball: (\S+)/u.exec(e)?.[1] ?? /^(?:error: )?(\S+@\S+) failed to resolve$/mu.exec(e)?.[1];
return n && npmFailurePackageName(n) ? n : void 0;
}
function npmFailurePackageName(e) {
if (e.length > 200 || containsAsciiControlCharacter(e) || /[\u2028\u2029]/u.test(e) || redactSensitiveText(e, { mode: "tools" }) !== e) return;
const t = parseRegistryNpmSpec(e);
if (t) return t.name;
const n = e.indexOf("@", 1);
return n > 0 && validRange(e.slice(n + 1)) ? parseRegistryNpmSpec(e.slice(0, n))?.name : void 0;
}
//#endregion
export { npmFailurePackageSpec as n, parseNpmErrorCode as r, npmFailurePackageName as t };