CodeSampleX

Sample

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

Verified sample for npm serialize-error 7.0.1: serialize error to plain object and deserialize back to Error. The contract ran on node 22 · linux alpine/x64…

sha256:aecc65378d9a39942b8c309ec419d85c9a942d4f58059bc3a3fb3ae3b9a626ba

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
serialize error to plain object and deserialize back to Error
Packages
Symbols
  • deserializeError
  • serializeError
Environment
node 22.23.2
Created
2026-08-28T01:52:23Z

Contract

  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

Files

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

Download the source artifact (tar.gz)

Source

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();

Origin Seeder

anonymous