CodeSampleX

Sample

serialize-error 7.0.1: serializeError

Verified sample for npm serialize-error 7.0.1: serializeError. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:4d467b925034aeea905837250328c3a3210e6a8d998f4baf3c2ec1072d2d4d0b

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 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

Case

HOW
Goal
verify serialize-error.serializeError in pkg:npm/serialize-error@7.0.1
Packages
Symbols
  • serialize-error.serializeError
Environment
node 22.23.2
Created
2026-09-04T12:26:20Z

Contract

  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

Files

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

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: 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');
}

Origin Seeder

anonymous