CodeSampleX

サンプル

cacheable-request 7.0.4: CacheError

検証済みサンプル — npm cacheable-request 7.0.4: CacheError. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: CacheError inherits from Error with name…

sha256:1f2ed5263bd34c66156143c9bbb09dd361cb02fa1903872b3aca33aee5616df9

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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

ケース

HOW
ゴール
verify cacheable-request.CacheError in pkg:npm/cacheable-request@7.0.4
パッケージ
シンボル
  • cacheable-request.CacheError
環境
node 22.23.2
作成日
2026-09-05T22:36:58Z

コントラクト

  1. CacheError inherits from Error with name CacheError and preserves error message
  2. CacheError copies custom properties and error codes from the underlying error
  3. CacheError can be constructed from an error-like object with message and properties
  4. CacheableRequest emits CacheError when cache backend operations throw

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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.CacheError 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.CacheError

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:5e68241181da3ef4c99032db19171d1ec8f08332e9154480116e1b340b72a769","contract":["CacheError inherits from Error with name CacheError and preserves error message","CacheError copies custom properties and error codes from the underlying error","CacheError can be constructed from an error-like object with message and properties","CacheableRequest emits CacheError when cache backend operations throw"],"goal":"verify cacheable-request.CacheError in pkg:npm/cacheable-request@7.0.4","kind":"HOW","packages":["pkg:npm/cacheable-request@7.0.4"],"schemaVersion":1,"symbols":["cacheable-request.CacheError"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","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.CacheError"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

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

/**
 * Creates a CacheError instance wrapping the given error.
 *
 * @param {Error|Object} error - Original error or object with error properties.
 * @returns {CacheableRequest.CacheError} Wrapped CacheError instance.
 */
function createCacheError(error) {
  return new CacheableRequest.CacheError(error);
}

/**
 * Determines whether the given value is an instance of CacheableRequest.CacheError.
 *
 * @param {unknown} value - Value to check.
 * @returns {boolean} True if value is a CacheError.
 */
function isCacheError(value) {
  return value instanceof CacheableRequest.CacheError;
}

module.exports = {
  CacheableRequest,
  CacheError: CacheableRequest.CacheError,
  createCacheError,
  isCacheError
};
package-lock.json
{
  "name": "sample-cacheable-request",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-cacheable-request",
      "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",
  "version": "1.0.0",
  "description": "Clean-room sample verifying cacheable-request.CacheError in pkg:npm/cacheable-request@7.0.4",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "cacheable-request": "7.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify cacheable-request.CacheError in pkg:npm/cacheable-request@7.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/cacheable-request@7.0.4"
  ],
  "symbols": [
    "cacheable-request.CacheError"
  ]
}
test/contract.cjs
const assert = require('node:assert/strict');
const CacheableRequest = require('cacheable-request');
const { CacheError, createCacheError, isCacheError } = require('../index.js');

async function runContractTests() {
  // 1. CacheError inherits from Error with name CacheError and preserves error message
  const originalError = new Error('Cache store read failure');
  const cacheError = new CacheError(originalError);

  assert.equal(cacheError instanceof Error, true, 'CacheError must be an instance of Error');
  assert.equal(cacheError instanceof CacheError, true, 'CacheError must be an instance of CacheableRequest.CacheError');
  assert.equal(cacheError.name, 'CacheError', 'CacheError name property must be "CacheError"');
  assert.equal(cacheError.message, 'Cache store read failure', 'CacheError must preserve underlying error message');
  assert.equal(isCacheError(cacheError), true, 'isCacheError must return true for CacheError instance');

  // 2. CacheError copies custom properties and error codes from the underlying error
  const detailedError = new Error('Connection timeout');
  detailedError.code = 'ETIMEDOUT';
  detailedError.errno = -110;
  const wrappedDetailed = createCacheError(detailedError);

  assert.equal(wrappedDetailed.code, 'ETIMEDOUT', 'CacheError must copy code property from underlying error');
  assert.equal(wrappedDetailed.errno, -110, 'CacheError must copy errno property from underlying error');
  assert.equal(wrappedDetailed.name, 'CacheError', 'Wrapped error name remains "CacheError"');

  // 3. CacheError can be constructed from an error-like object with message and properties
  const plainObjectError = { message: 'Failed to access key', code: 'ERR_KEY_ACCESS' };
  const wrappedPlain = new CacheError(plainObjectError);

  assert.equal(wrappedPlain instanceof Error, true, 'Wrapped object must be an instance of Error');
  assert.equal(wrappedPlain instanceof CacheError, true, 'Wrapped object must be an instance of CacheError');
  assert.equal(wrappedPlain.name, 'CacheError', 'Wrapped object name must be "CacheError"');
  assert.equal(wrappedPlain.message, 'Failed to access key', 'Wrapped object message must match');
  assert.equal(wrappedPlain.code, 'ERR_KEY_ACCESS', 'Wrapped object properties must be copied');

  // 4. CacheableRequest emits CacheError when cache backend operations throw
  const faultyCacheStore = {
    get: async () => {
      throw new Error('Keyv backend unreachable');
    },
    set: async () => {},
    delete: async () => {},
    clear: async () => {}
  };

  const dummyRequest = () => ({
    once: () => {},
    on: () => {},
    emit: () => {},
    end: () => {},
    abort: () => {}
  });

  const cacheable = new CacheableRequest(dummyRequest, faultyCacheStore);

  const emittedError = await new Promise((resolve, reject) => {
    const req = cacheable('http://example.com/test-endpoint');
    req.on('error', resolve);
    setTimeout(() => reject(new Error('Timed out waiting for CacheError to be emitted')), 2000);
  });

  assert.equal(isCacheError(emittedError), true, 'Emitted error must be an instance of CacheError');
  assert.equal(emittedError.name, 'CacheError', 'Emitted error name must be "CacheError"');
  assert.equal(emittedError.message, 'Keyv backend unreachable', 'Emitted error message must match backend error');

  console.log('All contract assertions passed.');
}

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

オリジンシーダー

匿名