CodeSampleX

示例

es-errors 1.3.0: eval, range, ref

已验证示例 — npm es-errors 1.3.0: eval, range, ref. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: Root export returns the built-in Error constructor…

sha256:50d251c0158c1a9fff164ec37da726cb3b4be3374319e7dec8135cc02d64cd72

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
2
声明的环境 node 22 linux x64 node 22 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19
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-09-12

案例

HOW
目标
verify pkg:npm/es-errors@1.3.0
包
符号
  • es-errors
  • es-errors/eval
  • es-errors/range
  • es-errors/ref
  • es-errors/syntax
  • es-errors/type
  • es-errors/uri
环境
node 22
创建时间
2026-08-18T18:05:07Z

契约

  1. Root export returns the built-in Error constructor reference
  2. es-errors/eval subpath exports the built-in EvalError constructor reference
  3. es-errors/range subpath exports the built-in RangeError constructor reference
  4. es-errors/ref subpath exports the built-in ReferenceError constructor reference
  5. es-errors/syntax subpath exports the built-in SyntaxError constructor reference
  6. es-errors/type subpath exports the built-in TypeError constructor reference
  7. es-errors/uri subpath exports the built-in URIError constructor reference
  8. Constructed error instances inherit from Error and their specific constructor with expected name and message properties
  9. Constructors called as functions return valid error instances
  10. getErrorConstructor routes string identifiers to corresponding Error constructors
  11. createError constructs error instances matching expected constructors and messages

文件

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

下载源代码构件 (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 pkg:npm/es-errors@1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/es-errors@1.3.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:8634ad3ac73653522b03f0a7603cfd24b80373db85e7e91d74be80fa1ec2ac3e","constraints":{"executionContext":"node"},"contract":["Root export returns the built-in Error constructor reference","es-errors/eval subpath exports the built-in EvalError constructor reference","es-errors/range subpath exports the built-in RangeError constructor reference","es-errors/ref subpath exports the built-in ReferenceError constructor reference","es-errors/syntax subpath exports the built-in SyntaxError constructor reference","es-errors/type subpath exports the built-in TypeError constructor reference","es-errors/uri subpath exports the built-in URIError constructor reference","Constructed error instances inherit from Error and their specific constructor with expected name and message properties","Constructors called as functions return valid error instances","getErrorConstructor routes string identifiers to corresponding Error constructors","createError constructs error instances matching expected constructors and messages"],"goal":"verify pkg:npm/es-errors@1.3.0","kind":"HOW","packages":["pkg:npm/es-errors@1.3.0"],"schemaVersion":1,"symbols":["es-errors","es-errors/eval","es-errors/range","es-errors/ref","es-errors/syntax","es-errors/type","es-errors/uri"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"linux","packageManager":"npm","packageManagerVersion":"10","runtime":"node","runtimeVersion":"22","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/es-errors@1.3.0"],"schemaVersion":1,"symbols":["es-errors","es-errors/eval","es-errors/range","es-errors/ref","es-errors/syntax","es-errors/type","es-errors/uri"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

var $Error = require('es-errors');
var $EvalError = require('es-errors/eval');
var $RangeError = require('es-errors/range');
var $RefError = require('es-errors/ref');
var $SyntaxError = require('es-errors/syntax');
var $TypeError = require('es-errors/type');
var $URIError = require('es-errors/uri');

function getErrorConstructor(type) {
  switch (type) {
    case 'eval':
      return $EvalError;
    case 'range':
      return $RangeError;
    case 'ref':
    case 'reference':
      return $RefError;
    case 'syntax':
      return $SyntaxError;
    case 'type':
      return $TypeError;
    case 'uri':
      return $URIError;
    default:
      return $Error;
  }
}

function createError(type, message) {
  var Ctor = getErrorConstructor(type);
  return new Ctor(message);
}

module.exports = {
  Error: $Error,
  EvalError: $EvalError,
  RangeError: $RangeError,
  ReferenceError: $RefError,
  SyntaxError: $SyntaxError,
  TypeError: $TypeError,
  URIError: $URIError,
  getErrorConstructor: getErrorConstructor,
  createError: createError
};
package-lock.json
{
  "name": "sample-es-errors",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-es-errors",
      "version": "1.0.0",
      "dependencies": {
        "es-errors": "1.3.0"
      }
    },
    "node_modules/es-errors": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
      "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    }
  }
}
package.json
{
  "name": "sample-es-errors",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of es-errors package",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "es-errors": "1.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/es-errors@1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/es-errors@1.3.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.js
'use strict';

var assert = require('assert');
var sample = require('../index.js');

var $Error = sample.Error;
var $EvalError = sample.EvalError;
var $RangeError = sample.RangeError;
var $RefError = sample.ReferenceError;
var $SyntaxError = sample.SyntaxError;
var $TypeError = sample.TypeError;
var $URIError = sample.URIError;
var getErrorConstructor = sample.getErrorConstructor;
var createError = sample.createError;

// 1. Root and subpath intrinsic exports match global Error constructors
assert.strictEqual($Error, Error);
assert.strictEqual($EvalError, EvalError);
assert.strictEqual($RangeError, RangeError);
assert.strictEqual($RefError, ReferenceError);
assert.strictEqual($SyntaxError, SyntaxError);
assert.strictEqual($TypeError, TypeError);
assert.strictEqual($URIError, URIError);

// 2. Direct require checks from subpaths
assert.strictEqual(require('es-errors'), Error);
assert.strictEqual(require('es-errors/eval'), EvalError);
assert.strictEqual(require('es-errors/range'), RangeError);
assert.strictEqual(require('es-errors/ref'), ReferenceError);
assert.strictEqual(require('es-errors/syntax'), SyntaxError);
assert.strictEqual(require('es-errors/type'), TypeError);
assert.strictEqual(require('es-errors/uri'), URIError);

// 3. Constructed error instances have expected names, messages, and prototype chains
var err = new $Error('base error');
assert.strictEqual(err instanceof Error, true);
assert.strictEqual(err.name, 'Error');
assert.strictEqual(err.message, 'base error');

var evalErr = new $EvalError('eval failed');
assert.strictEqual(evalErr instanceof EvalError, true);
assert.strictEqual(evalErr instanceof Error, true);
assert.strictEqual(evalErr.name, 'EvalError');
assert.strictEqual(evalErr.message, 'eval failed');

var rangeErr = new $RangeError('out of bounds');
assert.strictEqual(rangeErr instanceof RangeError, true);
assert.strictEqual(rangeErr instanceof Error, true);
assert.strictEqual(rangeErr.name, 'RangeError');
assert.strictEqual(rangeErr.message, 'out of bounds');

var refErr = new $RefError('invalid reference');
assert.strictEqual(refErr instanceof ReferenceError, true);
assert.strictEqual(refErr instanceof Error, true);
assert.strictEqual(refErr.name, 'ReferenceError');
assert.strictEqual(refErr.message, 'invalid reference');

var syntaxErr = new $SyntaxError('unexpected token');
assert.strictEqual(syntaxErr instanceof SyntaxError, true);
assert.strictEqual(syntaxErr instanceof Error, true);
assert.strictEqual(syntaxErr.name, 'SyntaxError');
assert.strictEqual(syntaxErr.message, 'unexpected token');

var typeErr = new $TypeError('value is not expected type');
assert.strictEqual(typeErr instanceof TypeError, true);
assert.strictEqual(typeErr instanceof Error, true);
assert.strictEqual(typeErr.name, 'TypeError');
assert.strictEqual(typeErr.message, 'value is not expected type');

var uriErr = new $URIError('malformed URI sequence');
assert.strictEqual(uriErr instanceof URIError, true);
assert.strictEqual(uriErr instanceof Error, true);
assert.strictEqual(uriErr.name, 'URIError');
assert.strictEqual(uriErr.message, 'malformed URI sequence');

// 4. Calling constructor as a function (without new) returns Error instance
var calledTypeErr = $TypeError('called type error');
assert.strictEqual(calledTypeErr instanceof TypeError, true);
assert.strictEqual(calledTypeErr.message, 'called type error');

// 5. getErrorConstructor helper correctly routes error names
assert.strictEqual(getErrorConstructor('eval'), EvalError);
assert.strictEqual(getErrorConstructor('range'), RangeError);
assert.strictEqual(getErrorConstructor('ref'), ReferenceError);
assert.strictEqual(getErrorConstructor('reference'), ReferenceError);
assert.strictEqual(getErrorConstructor('syntax'), SyntaxError);
assert.strictEqual(getErrorConstructor('type'), TypeError);
assert.strictEqual(getErrorConstructor('uri'), URIError);
assert.strictEqual(getErrorConstructor('unknown'), Error);

// 6. createError helper creates instance matching target constructor
var helperErr = createError('range', 'helper index error');
assert.strictEqual(helperErr instanceof RangeError, true);
assert.strictEqual(helperErr.message, 'helper index error');

console.log('PASS: es-errors contract verified');

原始种子者

匿名