CodeSampleX

Beispiel

cacheable-request 7.0.4: RequestError

Verifiziertes Beispiel für npm cacheable-request 7.0.4: RequestError. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:90f8110ac098a9a5317eff02c5ed90b96a94d297e7571993fd59b53873557b07

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-05

Fall

HOW
Ziel
verify cacheable-request.RequestError in pkg:npm/cacheable-request@7.0.4
Pakete
Symbole
  • cacheable-request.RequestError
Erstellt
2026-09-05T23:17:42Z

Contract

  1. RequestError is exported as a static property on CacheableRequest
  2. RequestError inherits from the JavaScript Error class
  3. RequestError instances have name set to RequestError
  4. RequestError constructor initializes error message from source error
  5. RequestError copies custom properties like code and syscall from source error
  6. RequestError maintains a valid stack trace starting with RequestError name
  7. CacheableRequest emits RequestError when underlying request function throws synchronously
  8. Emitted error from throwing request is an instance of CacheableRequest.RequestError

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify cacheable-request.RequestError in pkg:npm/cacheable-request@7.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/cacheable-request@7.0.4
Demonstrate these symbols/APIs:
  - cacheable-request.RequestError

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:1b0943d3d08220f63e05c5761529ea798f81247d93c1573253ddac4c5d303eeb","contract":["RequestError is exported as a static property on CacheableRequest","RequestError inherits from the JavaScript Error class","RequestError instances have name set to RequestError","RequestError constructor initializes error message from source error","RequestError copies custom properties like code and syscall from source error","RequestError maintains a valid stack trace starting with RequestError name","CacheableRequest emits RequestError when underlying request function throws synchronously","Emitted error from throwing request is an instance of CacheableRequest.RequestError"],"goal":"verify cacheable-request.RequestError in pkg:npm/cacheable-request@7.0.4","kind":"HOW","packages":["pkg:npm/cacheable-request@7.0.4"],"schemaVersion":1,"symbols":["cacheable-request.RequestError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/cacheable-request@7.0.4"],"schemaVersion":1,"subject":"pkg:npm/cacheable-request@7.0.4","symbols":["cacheable-request.RequestError"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-cacheable-request-error",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-cacheable-request-error",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "cacheable-request": "7.0.4"
      }
    },
    "node_modules/cacheable-request": {
      "version": "7.0.4",
      "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.4.tgz",
      "integrity": "sha512-v+p6ongsrp0yTGbJXjgxPow2+DL93DASP4kXCDKb8/bwRtt9OEF3whggkkDkGNzgcWy2XaF4a8nZglC7uElscg==",
      "license": "MIT",
      "dependencies": {
        "clone-response": "^1.0.2",
        "get-stream": "^5.1.0",
        "http-cache-semantics": "^4.0.0",
        "keyv": "^4.0.0",
        "lowercase-keys": "^2.0.0",
        "normalize-url": "^6.0.1",
        "responselike": "^2.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/clone-response": {
      "version": "1.0.3",
      "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz",
      "integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==",
      "license": "MIT",
      "dependencies": {
        "mimic-response": "^1.0.0"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/end-of-stream": {
      "version": "1.4.5",
      "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",
      "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",
      "license": "MIT",
      "dependencies": {
        "once": "^1.4.0"
      }
    },
    "node_modules/get-stream": {
      "version": "5.2.0",
      "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
      "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
      "license": "MIT",
      "dependencies": {
        "pump": "^3.0.0"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/http-cache-semantics": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.2.0.tgz",
      "integrity": "sha512-dTxcvPXqPvXBQpq5dUr6mEMJX4oIEFv6bwom3FDwKRDsuIjjJGANqhBuoAn9c1RQJIdAKav33ED65E2ys+87QQ==",
      "license": "BSD-2-Clause"
    },
    "node_modules/json-buffer": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
      "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==",
      "license": "MIT"
    },
    "node_modules/keyv": {
      "version": "4.5.4",
      "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
      "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==",
      "license": "MIT",
      "dependencies": {
        "json-buffer": "3.0.1"
      }
    },
    "node_modules/lowercase-keys": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
      "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/mimic-response": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
      "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    },
    "node_modules/normalize-url": {
      "version": "6.1.0",
      "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
      "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
      "license": "ISC",
      "dependencies": {
        "wrappy": "1"
      }
    },
    "node_modules/pump": {
      "version": "3.0.4",
      "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz",
      "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==",
      "license": "MIT",
      "dependencies": {
        "end-of-stream": "^1.1.0",
        "once": "^1.3.1"
      }
    },
    "node_modules/responselike": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz",
      "integrity": "sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==",
      "license": "MIT",
      "dependencies": {
        "lowercase-keys": "^2.0.0"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-cacheable-request-error",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for cacheable-request.RequestError in cacheable-request@7.0.4",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "cacheable-request": "7.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify cacheable-request.RequestError in pkg:npm/cacheable-request@7.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/cacheable-request@7.0.4"
  ],
  "symbols": [
    "cacheable-request.RequestError"
  ]
}
src/index.js
'use strict';

const CacheableRequest = require('cacheable-request');

/**
 * Creates a request handler wrapped with CacheableRequest.
 *
 * @param {Function} request - The underlying HTTP request function.
 * @param {Object|string} [cacheAdapter] - Optional cache storage adapter or connection string.
 * @returns {Function} Request function wrapped with caching logic.
 */
function createCacheableRequest(request, cacheAdapter) {
  return new CacheableRequest(request, cacheAdapter);
}

/**
 * Wraps a low-level error into CacheableRequest.RequestError.
 *
 * @param {Error} error - The underlying error.
 * @returns {CacheableRequest.RequestError} RequestError instance.
 */
function createRequestError(error) {
  return new CacheableRequest.RequestError(error);
}

module.exports = {
  CacheableRequest,
  RequestError: CacheableRequest.RequestError,
  createCacheableRequest,
  createRequestError
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  CacheableRequest,
  RequestError,
  createCacheableRequest,
  createRequestError
} = require('../src/index.js');

async function testAll() {
  // 1. RequestError is exported as a static property on CacheableRequest
  assert.equal(typeof RequestError, 'function', 'RequestError must be a function / class');
  assert.equal(CacheableRequest.RequestError, RequestError, 'CacheableRequest.RequestError must reference the same class');

  // 2. RequestError inherits from the JavaScript Error class
  const dummyError = new Error('origin request failed');
  const reqError = new RequestError(dummyError);
  assert.ok(reqError instanceof Error, 'RequestError instance must be an instance of Error');
  assert.ok(reqError instanceof RequestError, 'RequestError instance must be an instance of RequestError');
  assert.ok(reqError instanceof CacheableRequest.RequestError, 'RequestError instance must be an instance of CacheableRequest.RequestError');

  // 3. RequestError instances have name set to RequestError
  assert.equal(reqError.name, 'RequestError', 'reqError.name must be RequestError');

  // 4. RequestError constructor initializes error message from source error
  assert.equal(reqError.message, 'origin request failed', 'reqError.message must equal source error message');

  // 5. RequestError copies custom properties like code and syscall from source error
  const customPropsError = new Error('custom error');
  customPropsError.code = 'ECONNREFUSED';
  customPropsError.syscall = 'connect';
  customPropsError.address = '127.0.0.1';
  customPropsError.port = 8080;
  customPropsError.metadata = { attempts: 3 };

  const customReqError = createRequestError(customPropsError);
  assert.equal(customReqError.code, 'ECONNREFUSED');
  assert.equal(customReqError.syscall, 'connect');
  assert.equal(customReqError.address, '127.0.0.1');
  assert.equal(customReqError.port, 8080);
  assert.deepEqual(customReqError.metadata, { attempts: 3 });

  // 6. RequestError maintains a valid stack trace starting with RequestError name
  assert.ok(typeof customReqError.stack === 'string' && customReqError.stack.length > 0, 'stack trace must be present');
  assert.ok(customReqError.stack.startsWith('RequestError: custom error'), 'stack trace must start with RequestError name and message');

  // 7. CacheableRequest emits RequestError when underlying request function throws synchronously
  const throwingRequest = () => {
    const err = new Error('immediate network failure');
    err.code = 'ENETUNREACH';
    throw err;
  };
  const cacheable = createCacheableRequest(throwingRequest);
  let caughtError = null;

  await new Promise((resolve) => {
    const reqEmitter = cacheable('http://localhost:8080/path', () => {});
    reqEmitter.on('error', (err) => {
      caughtError = err;
      resolve();
    });
  });

  assert.ok(caughtError !== null, 'CacheableRequest must emit an error event');
  assert.equal(caughtError.name, 'RequestError', 'Emitted error name must be RequestError');
  assert.equal(caughtError.message, 'immediate network failure', 'Emitted error message must match thrown error');
  assert.equal(caughtError.code, 'ENETUNREACH', 'Emitted error must carry thrown error code');

  // 8. Emitted error from throwing request is an instance of CacheableRequest.RequestError
  assert.ok(caughtError instanceof RequestError, 'Emitted error must be an instance of RequestError');
  assert.ok(caughtError instanceof Error, 'Emitted error must be an instance of Error');

  console.log('All cacheable-request.RequestError contract tests passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

Ursprungs-Seeder

anonym