CodeSampleX

Exemplo

socks 2.8.9: SocksClientError

Amostra verificada para npm socks 2.8.9: SocksClientError. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: assert SocksClientError is an…

sha256:c9bb71b18a2a435767fa1e9feac89a549666e034faf875908410b0e873176836

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23

Caso

HOW
Objetivo
verify socks.SocksClientError in pkg:npm/socks@2.8.9
Pacotes
Símbolos
  • socks.SocksClientError
Criado
2026-08-23T13:40:31Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/socks@2.8.9
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:4c9dd4f2f0dcf92d91dd95e1b1541a006d44dadefef1643ebcb2947127599199","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.9","kind":"HOW","packages":["pkg:npm/socks@2.8.9"],"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.9"],"schemaVersion":1,"subject":"pkg:npm/socks@2.8.9","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.9"
      }
    },
    "node_modules/ip-address": {
      "version": "10.5.0",
      "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.5.0.tgz",
      "integrity": "sha512-R5SnVLJmgYYvf2F2ZgwSBnelz5G4q5AxIC277GDfUaNbrZKNANcBC7RHqYYePlszf4kBolVkJauG0ZjHHFh55g==",
      "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.9",
      "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.9.tgz",
      "integrity": "sha512-LJhUYUvItdQ0LkJTmPeaEObWXAqFyfmP85x0tch/ez9cahmhlBBLbIqDFnvBnUJGagb0JbIQrkBs1wJ+yRYpEw==",
      "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.9"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify socks.SocksClientError in pkg:npm/socks@2.8.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/socks@2.8.9"
  ],
  "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.');

Seeder de origem

anônimo