CodeSampleX

サンプル

socks 2.8.10: SocksClientError

検証済みサンプル — npm socks 2.8.10: SocksClientError. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: assert SocksClientError is an instance of Error

sha256:1103a36b263edfdc606446ecd9249633a8e7068eecebd4d0c0c5ceb505ba4ca9

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify socks.SocksClientError in pkg:npm/socks@2.8.10
パッケージ
シンボル
  • socks.SocksClientError
作成日
2026-09-07T03:02:56Z

コントラクト

  1. assert SocksClientError is an instance of Error
  2. assert SocksClientError retains error message and client options
  3. assert SocksClient emits or rejects with SocksClientError on connection failure

ファイル

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

ソースアーティファクトをダウンロード (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 socks.SocksClientError in pkg:npm/socks@2.8.10
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks@2.8.10
Demonstrate these symbols/APIs:
  - socks.SocksClientError

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:2d611ca23e8f3524246f6091a44c612fa631294d751827ad265e7c412bd59a39","contract":["assert SocksClientError is an instance of Error","assert SocksClientError retains error message and client options","assert SocksClient emits or rejects with SocksClientError on connection failure"],"goal":"verify socks.SocksClientError in pkg:npm/socks@2.8.10","kind":"HOW","packages":["pkg:npm/socks@2.8.10"],"schemaVersion":1,"symbols":["socks.SocksClientError"]},"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/socks@2.8.10"],"schemaVersion":1,"subject":"pkg:npm/socks@2.8.10","symbols":["socks.SocksClientError"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { SocksClient, SocksClientError } from 'socks';

/**
 * Creates a SocksClient error with custom options.
 * @param {string} message
 * @param {object} options
 * @returns {SocksClientError}
 */
export function createClientError(message, options) {
  return new SocksClientError(message, options);
}

/**
 * Attempts to connect through a SOCKS proxy, catching any SocksClientError.
 * @param {object} options
 * @returns {Promise<object>}
 */
export async function attemptConnection(options) {
  try {
    const info = await SocksClient.createConnection(options);
    return { success: true, info };
  } catch (err) {
    if (err instanceof SocksClientError) {
      return { success: false, error: err };
    }
    throw err;
  }
}

export { SocksClient, SocksClientError };
package-lock.json
{
  "name": "socks-client-error-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "socks-client-error-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "socks": "2.8.10"
      }
    },
    "node_modules/ip-address": {
      "version": "10.7.0",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.0.tgz",
      "integrity": "sha512-BGFsyJd5mpXp3rK6jIdADLNgpJUK1jnjzvYF8lK+VyDab9JAmqN0YOKDdP17HlgKb2+ehPgDc8EtnRLbGCAMhA==",
      "license": "MIT",
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/smart-buffer": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
      "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
      "license": "MIT",
      "engines": {
        "node": ">= 6.0.0",
        "npm": ">= 3.0.0"
      }
    },
    "node_modules/socks": {
      "version": "2.8.10",
      "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.10.tgz",
      "integrity": "sha512-e0VyvkVTwVYViNovRkZ9aodhxVlyoMn7eJhVUPxZ+eK9P/7CBkxvvsBOHqFPEH416726W8tLXXXjKwqgTErrCQ==",
      "license": "MIT",
      "dependencies": {
        "ip-address": "^10.1.1",
        "smart-buffer": "^4.2.0"
      },
      "engines": {
        "node": ">= 10.0.0",
        "npm": ">= 3.0.0"
      }
    }
  }
}
package.json
{
  "name": "socks-client-error-sample",
  "version": "1.0.0",
  "description": "Demonstrate socks.SocksClientError usage and behavior",
  "main": "index.mjs",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "socks": "2.8.10"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socks.SocksClientError in pkg:npm/socks@2.8.10",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks@2.8.10"
  ],
  "symbols": [
    "socks.SocksClientError"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { SocksClient, SocksClientError } from 'socks';
import { createClientError, attemptConnection } from '../index.mjs';

// 1. Assert SocksClientError class exists and extends Error
assert.equal(typeof SocksClientError, 'function', 'SocksClientError should be a constructor function');
const sampleOptions = {
  proxy: {
    ipaddress: '127.0.0.1',
    port: 1080,
    type: 5
  },
  command: 'connect',
  destination: {
    host: 'localhost',
    port: 80
  }
};

const customError = createClientError('connection failed to proxy', sampleOptions);
assert(customError instanceof Error, 'customError must be an instance of Error');
assert(customError instanceof SocksClientError, 'customError must be an instance of SocksClientError');
assert.equal(customError.message, 'connection failed to proxy', 'error message must match');
assert.deepEqual(customError.options, sampleOptions, 'error options must match');

// 2. Assert SocksClient.createConnection emits/rejects with SocksClientError on unreachable proxy
const unreachableOptions = {
  proxy: {
    ipaddress: '127.0.0.1',
    port: 59998,
    type: 5
  },
  command: 'connect',
  destination: {
    host: '127.0.0.1',
    port: 8080
  },
  timeout: 1000
};

const result = await attemptConnection(unreachableOptions);
assert.equal(result.success, false, 'connection should fail on closed port');
assert(result.error instanceof SocksClientError, 'error should be an instance of SocksClientError');
assert(result.error instanceof Error, 'error should be an instance of Error');
assert(result.error.message.length > 0, 'error message should not be empty');
assert.equal(result.error.options.proxy.port, 59998, 'error options proxy port should match');

console.log('All contract tests passed.');

オリジンシーダー

匿名