or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-pnpm--error

Specialized error classes for pnpm package manager operations

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@pnpm/error@1000.0.x

To install, run

npx @tessl/cli install tessl/npm-pnpm--error@1000.0.0

index.mddocs/

@pnpm/error

@pnpm/error provides specialized error classes for pnpm package manager operations. It offers typed error handling for general pnpm errors, HTTP fetch failures, and lockfile inconsistency issues with built-in support for error code standardization and authentication token masking.

Package Information

  • Package Name: @pnpm/error
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @pnpm/error

Core Imports

import { PnpmError, FetchError, LockfileMissingDependencyError } from "@pnpm/error";
import type { FetchErrorResponse, FetchErrorRequest } from "@pnpm/error";

For CommonJS:

const { PnpmError, FetchError, LockfileMissingDependencyError } = require("@pnpm/error");

Basic Usage

import { PnpmError, FetchError, LockfileMissingDependencyError } from "@pnpm/error";

// General pnpm error
try {
  throw new PnpmError("THE_ERROR_CODE", "Something went wrong", {
    hint: "Try running with --verbose for more details"
  });
} catch (err) {
  console.log(err.code); // "ERR_PNPM_THE_ERROR_CODE"
  console.log(err.message); // "Something went wrong"
  console.log(err.hint); // "Try running with --verbose for more details"
}

// HTTP fetch error
const fetchError = new FetchError(
  { url: "https://registry.npmjs.org/some-package" },
  { status: 404, statusText: "Not Found" }
);

// Lockfile dependency error
const lockfileError = new LockfileMissingDependencyError("some-dep@1.0.0");

Capabilities

Base Error Class

Core error class for all pnpm-related errors with automatic error code prefixing and optional hints.

class PnpmError extends Error {
  /** Error code, automatically prefixed with 'ERR_PNPM_' if not already present */
  readonly code: string;
  /** Optional hint for resolving the error */
  readonly hint?: string;
  /** Number of attempts made before the error occurred */
  attempts?: number;
  /** Prefix associated with the error context */
  prefix?: string;
  /** Stack of packages associated with the error */
  pkgsStack?: Array<{ id: string, name: string, version: string }>;

  constructor(
    code: string,
    message: string,
    opts?: {
      attempts?: number;
      hint?: string;
    }
  );
}

HTTP Fetch Error Handling

Specialized error class for HTTP request failures with automatic authentication token masking for security.

class FetchError extends PnpmError {
  /** Response information from the failed HTTP request */
  readonly response: FetchErrorResponse;
  /** Request information with authentication details masked for security */
  readonly request: FetchErrorRequest;

  /**
   * Creates a fetch error with automatic authentication token masking
   * @param request - Request details including URL and optional auth header
   * @param response - Response details with status code and message
   * @param hint - Optional additional hint for error resolution
   * @remarks The constructor automatically masks auth tokens in the request object for security
   */
  constructor(
    request: FetchErrorRequest,
    response: FetchErrorResponse,
    hint?: string
  );
}

Lockfile Dependency Errors

Error class for lockfile inconsistency issues with built-in resolution hints.

class LockfileMissingDependencyError extends PnpmError {
  /**
   * Creates an error for missing lockfile dependencies with automatic hint
   * @param depPath - The dependency path that is missing from the lockfile
   * @remarks Uses WANTED_LOCKFILE constant from @pnpm/constants to reference the lockfile name
   */
  constructor(depPath: string);
}

Types

interface FetchErrorResponse {
  /** HTTP status code from the failed request */
  status: number;
  /** HTTP status text from the failed request */
  statusText: string;
}

interface FetchErrorRequest {
  /** The URL that was being requested */
  url: string;
  /** Optional authorization header value (will be masked in error output) */
  authHeaderValue?: string;
}

Error Code Standardization

All PnpmError instances automatically standardize error codes:

  • Codes are prefixed with "ERR_PNPM_" if not already present
  • FetchError uses codes like "ERR_PNPM_FETCH_404", "ERR_PNPM_FETCH_401"
  • LockfileMissingDependencyError uses "ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY"

Security Features

FetchError automatically masks authentication information in error messages and request objects:

  • Long tokens (≥20 characters): Shows first 4 characters + "[hidden]" (e.g., "Bearer 1234[hidden]")
  • Short tokens (<20 characters): Shows auth type + "[hidden]" (e.g., "Bearer [hidden]")
  • Malformed auth headers (no auth type): Shows only "[hidden]"
  • For 401, 403, and 404 status codes, adds helpful hint about authorization

This prevents sensitive authentication tokens from appearing in logs or error reports.