{
  "version": 3,
  "sources": ["../../../../src/packages/error/index.ts"],
  "sourcesContent": ["import { WANTED_LOCKFILE } from '../constants/index.ts';\n\nexport class PnpmError extends Error {\n  readonly code: string;\n  readonly hint?: string | undefined;\n  attempts?: number | undefined;\n  prefix?: string | undefined;\n  pkgsStack?: Array<{ id: string; name: string; version: string }> | undefined;\n  constructor(\n    code: string,\n    message: string,\n    opts?:\n      | {\n          attempts?: number | undefined;\n          hint?: string | undefined;\n        }\n      | undefined\n  ) {\n    super(message);\n    this.code = code.startsWith('ERR_PNPM_') ? code : `ERR_PNPM_${code}`;\n    this.hint = opts?.hint;\n    this.attempts = opts?.attempts;\n  }\n}\n\nexport type FetchErrorResponse = {\n  status: number;\n  statusText: string;\n};\n\nexport type FetchErrorRequest = {\n  url: string;\n  authHeaderValue?: string | undefined;\n};\n\nexport class FetchError extends PnpmError {\n  readonly response: FetchErrorResponse;\n  readonly request: FetchErrorRequest;\n\n  constructor(\n    request: FetchErrorRequest,\n    response: FetchErrorResponse,\n    hint?: string | undefined\n  ) {\n    const _request: FetchErrorRequest = {\n      url: request.url,\n    };\n\n    if (\n      typeof request.authHeaderValue === 'string' &&\n      request.authHeaderValue !== ''\n    ) {\n      _request.authHeaderValue = hideAuthInformation(request.authHeaderValue);\n    }\n\n    const message = `GET ${request.url}: ${response.statusText} - ${response.status}`;\n\n    let h = '';\n    // NOTE: For security reasons, some registries respond with 404 on authentication errors as well.\n    // So we print authorization info on 404 errors as well.\n    if (\n      response.status === 401 ||\n      response.status === 403 ||\n      response.status === 404\n    ) {\n      h = typeof hint === 'string' ? `${hint}\\n\\n` : '';\n\n      h +=\n        typeof _request.authHeaderValue === 'string' &&\n        _request.authHeaderValue !== ''\n          ? `An authorization header was used: ${_request.authHeaderValue}`\n          : 'No authorization header was set for the request.';\n    }\n\n    super(`FETCH_${response.status}`, message, { hint: h });\n    this.request = _request;\n    this.response = response;\n  }\n}\n\nfunction hideAuthInformation(authHeaderValue: string): string {\n  const [authType, token] = authHeaderValue.split(' ');\n\n  if (token == null) {\n    return '[hidden]';\n  }\n\n  if (token.length < 20) {\n    return `${authType} [hidden]`;\n  }\n\n  return `${authType} ${token.substring(0, 4)}[hidden]`;\n}\n\nexport class LockfileMissingDependencyError extends PnpmError {\n  constructor(depPath: string) {\n    const message = `Broken lockfile: no entry for '${depPath}' in ${WANTED_LOCKFILE}`;\n    super('LOCKFILE_MISSING_DEPENDENCY', message, {\n      hint:\n        'This issue is probably caused by a badly resolved merge conflict.\\n' +\n        \"To fix the lockfile, run 'pnpm install --no-frozen-lockfile'.\",\n    });\n  }\n}\n"],
  "mappings": "AAAA,SAAS,uBAAuB;AAEzB,MAAM,kBAAkB,MAAM;AAAA,EAC1B;AAAA,EACA;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,YACE,MACA,SACA,MAMA;AACA,UAAM,OAAO;AACb,SAAK,OAAO,KAAK,WAAW,WAAW,IAAI,OAAO,YAAY,IAAI;AAClE,SAAK,OAAO,MAAM;AAClB,SAAK,WAAW,MAAM;AAAA,EACxB;AACF;AAYO,MAAM,mBAAmB,UAAU;AAAA,EAC/B;AAAA,EACA;AAAA,EAET,YACE,SACA,UACA,MACA;AACA,UAAM,WAA8B;AAAA,MAClC,KAAK,QAAQ;AAAA,IACf;AAEA,QACE,OAAO,QAAQ,oBAAoB,YACnC,QAAQ,oBAAoB,IAC5B;AACA,eAAS,kBAAkB,oBAAoB,QAAQ,eAAe;AAAA,IACxE;AAEA,UAAM,UAAU,OAAO,QAAQ,GAAG,KAAK,SAAS,UAAU,MAAM,SAAS,MAAM;AAE/E,QAAI,IAAI;AAGR,QACE,SAAS,WAAW,OACpB,SAAS,WAAW,OACpB,SAAS,WAAW,KACpB;AACA,UAAI,OAAO,SAAS,WAAW,GAAG,IAAI;AAAA;AAAA,IAAS;AAE/C,WACE,OAAO,SAAS,oBAAoB,YACpC,SAAS,oBAAoB,KACzB,qCAAqC,SAAS,eAAe,KAC7D;AAAA,IACR;AAEA,UAA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