CodeSampleX

샘플

serialize-error 7.0.1: serialize error to plain object and deserialize back to Error

검증된 샘플 — npm serialize-error 7.0.1: serialize error to plain object and deserialize back to Error. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:aecc65378d9a39942b8c309ec419d85c9a942d4f58059bc3a3fb3ae3b9a626ba

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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-28

케이스

HOW
목표
serialize error to plain object and deserialize back to Error
패키지
심벌
  • deserializeError
  • serializeError
환경
node 22.23.2
생성일
2026-08-28T01:52:23Z

컨트랙트

  1. serializeError converts an Error instance into a plain object preserving name, message, stack, code, and custom properties
  2. serializeError handles circular references in error properties by replacing them with '[Circular]'
  3. deserializeError converts a plain serialized error object back into an Error instance preserving custom properties

파일

  • 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: serialize error to plain object and deserialize back to Error
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/serialize-error@7.0.1
Demonstrate these symbols/APIs:
  - deserializeError
  - 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:3e072ba0527759a07ddf7d3e1cc13e27fdf2f2bb8fce215fe7df083f7a20af17","contract":["serializeError converts an Error instance into a plain object preserving name, message, stack, code, and custom properties","serializeError handles circular references in error properties by replacing them with '[Circular]'","deserializeError converts a plain serialized error object back into an Error instance preserving custom properties"],"goal":"serialize error to plain object and deserialize back to Error","kind":"HOW","packages":["pkg:npm/serialize-error@7.0.1"],"schemaVersion":1,"symbols":["deserializeError","serializeError"]},"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/serialize-error@7.0.1"],"schemaVersion":1,"subject":"pkg:npm/serialize-error@7.0.1","symbols":["deserializeError","serializeError"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const { serializeError, deserializeError } = require('serialize-error');

function serialize(err, options) {
  return serializeError(err, options);
}

function deserialize(obj) {
  return deserializeError(obj);
}

module.exports = {
  serializeError,
  deserializeError,
  serialize,
  deserialize
};
package-lock.json
{
  "name": "sample-serialize-error",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-serialize-error",
      "version": "1.0.0",
      "license": "MIT-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",
  "version": "1.0.0",
  "private": true,
  "description": "serialize error to plain object and deserialize back to Error",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "serialize-error": "7.0.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "serialize error to plain object and deserialize back to Error",
  "kind": "HOW",
  "packages": [
    "pkg:npm/serialize-error@7.0.1"
  ],
  "symbols": [
    "deserializeError",
    "serializeError"
  ]
}
test/contract.cjs
'use strict';

const assert = require('assert');
const { serializeError, deserializeError, serialize, deserialize } = require('../index.js');

function run() {
  // 1. Basic error serialization with serializeError
  const originalError = new TypeError('invalid argument type');
  originalError.code = 'ERR_INVALID_ARG';
  originalError.customField = 'extra-debug-info';

  const serialized = serializeError(originalError);

  assert.strictEqual(typeof serialized, 'object', 'serializeError must return a plain object');
  assert.strictEqual(serialized.name, 'TypeError', 'serialized error must preserve name');
  assert.strictEqual(serialized.message, 'invalid argument type', 'serialized error must preserve message');
  assert.strictEqual(typeof serialized.stack, 'string', 'serialized error must include stack trace string');
  assert.strictEqual(serialized.code, 'ERR_INVALID_ARG', 'serialized error must preserve code property');
  assert.strictEqual(serialized.customField, 'extra-debug-info', 'serialized error must preserve custom properties');

  // Verify properties are enumerable in serialized object
  const keys = Object.keys(serialized);
  assert.ok(keys.includes('name'), 'name property should be enumerable in serialized object');
  assert.ok(keys.includes('message'), 'message property should be enumerable in serialized object');
  assert.ok(keys.includes('stack'), 'stack property should be enumerable in serialized object');

  // 2. Circular reference handling
  const circularError = new Error('circular error');
  const circularObj = { name: 'loop' };
  circularObj.self = circularObj;
  circularError.ref = circularObj;

  const serializedCircular = serializeError(circularError);
  assert.strictEqual(serializedCircular.message, 'circular error');
  assert.strictEqual(serializedCircular.ref.self, '[Circular]', 'circular reference must be replaced with [Circular]');

  // 3. Deserialization with deserializeError
  const deserialized = deserializeError(serialized);

  assert.ok(deserialized instanceof Error, 'deserializeError must return an Error instance');
  assert.strictEqual(deserialized.name, 'TypeError', 'deserialized error must restore name');
  assert.strictEqual(deserialized.message, 'invalid argument type', 'deserialized error must restore message');
  assert.strictEqual(deserialized.code, 'ERR_INVALID_ARG', 'deserialized error must restore code');
  assert.strictEqual(deserialized.customField, 'extra-debug-info', 'deserialized error must restore customField');
  assert.strictEqual(deserialized.stack, serialized.stack, 'deserialized error must restore stack');

  // 4. Non-error value handling
  const primitiveError = deserializeError('unexpected failure');
  assert.ok(primitiveError instanceof Error, 'deserializeError with string must return an Error instance');
  assert.strictEqual(primitiveError.name, 'NonError', 'deserializeError with non-error must create NonError');

  // Error pass-through
  const directError = new Error('pass-through');
  assert.strictEqual(deserializeError(directError), directError, 'deserializeError must pass through existing Error');

  // 5. Helper functions verification
  const helperSerialized = serialize(new Error('helper test'));
  assert.strictEqual(helperSerialized.message, 'helper test');

  const helperDeserialized = deserialize(helperSerialized);
  assert.ok(helperDeserialized instanceof Error);
  assert.strictEqual(helperDeserialized.message, 'helper test');

  console.log('Contract tests passed successfully.');
  process.exit(0);
}

run();

오리진 시더

익명