CodeSampleX

샘플

serialize-error 7.0.1: serializeError

검증된 샘플 — npm serialize-error 7.0.1: serializeError. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: serializeError serializes standard Error…

sha256:4d467b925034aeea905837250328c3a3210e6a8d998f4baf3c2ec1072d2d4d0b

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-04

케이스

HOW
목표
verify serialize-error.serializeError in pkg:npm/serialize-error@7.0.1
패키지
심벌
  • serialize-error.serializeError
환경
node 22.23.2
생성일
2026-09-04T12:26:20Z

컨트랙트

  1. serializeError serializes standard Error objects into plain objects with name, message, and stack
  2. serializeError preserves custom properties and error codes
  3. serializeError serializes custom Error subclasses preserving their specific name
  4. serializeError handles nested error objects
  5. serializeError handles circular references without throwing
  6. serializeError passes through primitive values and null
  7. serializeError serializes plain objects preserving structure
  8. serializeError converts thrown functions to descriptive string representation and omits function properties
  9. serializeError handles arrays and errors contained within arrays

파일

  • PROMPT.md
  • csx.json
  • index.js
  • 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 serialize-error.serializeError in pkg:npm/serialize-error@7.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/serialize-error@7.0.1
Demonstrate these symbols/APIs:
  - serialize-error.serializeError

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:89ced311d40f3ca90307384ec715142776053179b95c2199bb9d25c852984f7b","constraints":{"executionContext":"node"},"contract":["serializeError serializes standard Error objects into plain objects with name, message, and stack","serializeError preserves custom properties and error codes","serializeError serializes custom Error subclasses preserving their specific name","serializeError handles nested error objects","serializeError handles circular references without throwing","serializeError passes through primitive values and null","serializeError serializes plain objects preserving structure","serializeError converts thrown functions to descriptive string representation and omits function properties","serializeError handles arrays and errors contained within arrays"],"goal":"verify serialize-error.serializeError in pkg:npm/serialize-error@7.0.1","kind":"HOW","packages":["pkg:npm/serialize-error@7.0.1"],"schemaVersion":1,"symbols":["serialize-error.serializeError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/serialize-error@7.0.1"],"schemaVersion":1,"subject":"pkg:npm/serialize-error@7.0.1","symbols":["serialize-error.serializeError"],"verifierAdapter":"node-typescript@1"}
index.js
import { serializeError, deserializeError } from 'serialize-error';

export { serializeError, deserializeError };
package-lock.json
{
  "name": "sample-serialize-error-serialize-error",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-serialize-error-serialize-error",
      "version": "1.0.0",
      "dependencies": {
        "serialize-error": "7.0.1"
      }
    },
    "node_modules/serialize-error": {
      "version": "7.0.1",
      "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz",
      "integrity": "sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==",
      "license": "MIT",
      "dependencies": {
        "type-fest": "^0.13.1"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/type-fest": {
      "version": "0.13.1",
      "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz",
      "integrity": "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==",
      "license": "(MIT OR CC0-1.0)",
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    }
  }
}
package.json
{
  "name": "sample-serialize-error-serialize-error",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "serialize-error": "7.0.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify serialize-error.serializeError in pkg:npm/serialize-error@7.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/serialize-error@7.0.1"
  ],
  "symbols": [
    "serialize-error.serializeError"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { serializeError } from 'serialize-error';

// 1. serializeError serializes standard Error objects into plain objects with name, message, and stack
{
  const err = new Error('standard error message');
  const serialized = serializeError(err);

  assert.equal(typeof serialized, 'object');
  assert.equal(serialized.name, 'Error');
  assert.equal(serialized.message, 'standard error message');
  assert.equal(typeof serialized.stack, 'string');
  assert.ok(serialized.stack.includes('standard error message'));

  const json = JSON.stringify(serialized);
  assert.ok(json.includes('"name":"Error"'));
  assert.ok(json.includes('"message":"standard error message"'));
}

// 2. serializeError preserves custom properties and error codes
{
  const err = new Error('failed operation');
  err.code = 'ERR_OPERATION_FAILED';
  err.statusCode = 500;
  err.details = { retryable: false };

  const serialized = serializeError(err);
  assert.equal(serialized.code, 'ERR_OPERATION_FAILED');
  assert.equal(serialized.statusCode, 500);
  assert.deepEqual(serialized.details, { retryable: false });
}

// 3. serializeError serializes custom Error subclasses preserving their specific name
{
  const typeErr = new TypeError('invalid argument type');
  const serializedType = serializeError(typeErr);
  assert.equal(serializedType.name, 'TypeError');
  assert.equal(serializedType.message, 'invalid argument type');

  class CustomAppError extends Error {
    constructor(msg) {
      super(msg);
      this.name = 'CustomAppError';
    }
  }
  const customErr = new CustomAppError('custom application error');
  const serializedCustom = serializeError(customErr);
  assert.equal(serializedCustom.name, 'CustomAppError');
  assert.equal(serializedCustom.message, 'custom application error');
}

// 4. serializeError handles nested error objects
{
  const parent = new Error('parent error occurred');
  parent.cause = new Error('root cause failure');

  const serialized = serializeError(parent);
  assert.equal(serialized.name, 'Error');
  assert.equal(serialized.message, 'parent error occurred');
  assert.equal(typeof serialized.cause, 'object');
  assert.equal(serialized.cause.name, 'Error');
  assert.equal(serialized.cause.message, 'root cause failure');
  assert.equal(typeof serialized.cause.stack, 'string');
}

// 5. serializeError handles circular references without throwing
{
  const err = new Error('circular error');
  err.self = err;

  const serialized = serializeError(err);
  assert.equal(serialized.name, 'Error');
  assert.equal(serialized.self, '[Circular]');

  const a = new Error('cycle A');
  const b = new Error('cycle B');
  a.sibling = b;
  b.sibling = a;

  const serializedA = serializeError(a);
  assert.equal(serializedA.sibling.name, 'Error');
  assert.equal(serializedA.sibling.sibling, '[Circular]');
}

// 6. serializeError passes through primitive values and null
{
  assert.equal(serializeError('plain string error'), 'plain string error');
  assert.equal(serializeError(404), 404);
  assert.equal(serializeError(true), true);
  assert.equal(serializeError(false), false);
  assert.equal(serializeError(null), null);
  assert.equal(serializeError(undefined), undefined);
}

// 7. serializeError serializes plain objects preserving structure
{
  const plain = {
    message: 'plain error-like object',
    code: 'CUSTOM_CODE',
    nested: { count: 42 }
  };
  const serialized = serializeError(plain);
  assert.deepEqual(serialized, {
    message: 'plain error-like object',
    code: 'CUSTOM_CODE',
    nested: { count: 42 }
  });
}

// 8. serializeError converts thrown functions to descriptive string representation and omits function properties
{
  function sampleHandler() {}
  assert.equal(serializeError(sampleHandler), '[Function: sampleHandler]');
  assert.equal(serializeError(() => {}), '[Function: anonymous]');

  const err = new Error('error with method');
  err.action = () => {};
  const serialized = serializeError(err);
  assert.equal(serialized.action, undefined);
}

// 9. serializeError handles arrays and errors contained within arrays
{
  const err = new Error('batch validation failure');
  err.errors = [
    'field required',
    new RangeError('value out of bounds')
  ];

  const serialized = serializeError(err);
  assert.ok(Array.isArray(serialized.errors));
  assert.equal(serialized.errors[0], 'field required');
  assert.equal(serialized.errors[1].name, 'RangeError');
  assert.equal(serialized.errors[1].message, 'value out of bounds');
}

오리진 시더

익명