CodeSampleX

Ejemplo

@fastify/error 4.2.0: FastifyError

Muestra verificada para npm @fastify/error 4.2.0: FastifyError. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:19bb209ba17303f3565f9f2311c7d7781414412f6b1c7bd914d86e0adf5813c7

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-10-20

Caso

HOW
Objetivo
verify @fastify/error.FastifyError in pkg:npm/%40fastify/error@4.2.0
Paquetes
Símbolos
  • @fastify/error.FastifyError
Creado
2026-10-20T14:05:50Z

Contrato

  1. new FastifyError() and FastifyError() return an Error instance with name 'FastifyError', code 'FST_ERR', message 'Fastify Error', statusCode 500, and toString() 'FastifyError [FST_ERR]: Fastify Error'
  2. Errors created by constructors returned from createError(code, message, statusCode) satisfy `err instanceof FastifyError` via Symbol.hasInstance while formatting printf-style args and extracting a trailing `{ cause }` option
  3. Plain Error instances do not satisfy `instanceof FastifyError`, and generic FastifyError instances do not satisfy `instanceof` a specific custom error constructor

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 @fastify/error.FastifyError in pkg:npm/%40fastify/error@4.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40fastify/error@4.2.0
Demonstrate these symbols/APIs:
  - @fastify/error.FastifyError

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:45e1f3f0b2495c4b5fa75ab397aaec875b5a210440ecb11d3bec475494325efd","contract":["new FastifyError() and FastifyError() return an Error instance with name 'FastifyError', code 'FST_ERR', message 'Fastify Error', statusCode 500, and toString() 'FastifyError [FST_ERR]: Fastify Error'","Errors created by constructors returned from createError(code, message, statusCode) satisfy `err instanceof FastifyError` via Symbol.hasInstance while formatting printf-style args and extracting a trailing `{ cause }` option","Plain Error instances do not satisfy `instanceof FastifyError`, and generic FastifyError instances do not satisfy `instanceof` a specific custom error constructor"],"goal":"verify @fastify/error.FastifyError in pkg:npm/%40fastify/error@4.2.0","kind":"HOW","packages":["pkg:npm/%40fastify/error@4.2.0"],"schemaVersion":1,"symbols":["@fastify/error.FastifyError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40fastify/error@4.2.0"],"schemaVersion":1,"subject":"pkg:npm/%40fastify/error@4.2.0","symbols":["@fastify/error.FastifyError"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "fastify-error-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "fastify-error-sample",
      "version": "1.0.0",
      "dependencies": {
        "@fastify/error": "4.2.0"
      }
    },
    "node_modules/@fastify/error": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/@fastify/error/-/error-4.2.0.tgz",
      "integrity": "sha512-RSo3sVDXfHskiBZKBPRgnQTtIqpi/7zhJOEmAxCiBcM7d0uwdGdxLlsCaLzGs8v8NnxIRlfG0N51p5yFaOentQ==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/fastify"
        },
        {
          "type": "opencollective",
          "url": "https://opencollective.com/fastify"
        }
      ],
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "fastify-error-sample",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "@fastify/error": "4.2.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @fastify/error.FastifyError in pkg:npm/%40fastify/error@4.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40fastify/error@4.2.0"
  ],
  "symbols": [
    "@fastify/error.FastifyError"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict'
import { createError, FastifyError } from '@fastify/error'

// 1. Direct instantiation of generic FastifyError (with and without `new`)
const genericErr = new FastifyError()
assert.equal(genericErr.name, 'FastifyError')
assert.equal(genericErr.code, 'FST_ERR')
assert.equal(genericErr.message, 'Fastify Error')
assert.equal(genericErr.statusCode, 500)
assert.equal(genericErr.toString(), 'FastifyError [FST_ERR]: Fastify Error')
assert.ok(genericErr instanceof Error)
assert.ok(genericErr instanceof FastifyError)

const genericNoNew = FastifyError()
assert.ok(genericNoNew instanceof FastifyError)
assert.equal(genericNoNew.code, 'FST_ERR')

// 2. Custom error constructor created via createError is an instance of FastifyError via Symbol.hasInstance
const CustomError = createError('FST_ERR_CUSTOM', 'Custom failure: %s (%d)', 400)
const rootCause = new Error('underlying reason')
const customErr = new CustomError('invalid input', 42, { cause: rootCause })

assert.equal(customErr.name, 'FastifyError')
assert.equal(customErr.code, 'FST_ERR_CUSTOM')
assert.equal(customErr.statusCode, 400)
assert.equal(customErr.message, 'Custom failure: invalid input (42)')
assert.equal(customErr.cause, rootCause)
assert.equal(customErr.toString(), 'FastifyError [FST_ERR_CUSTOM]: Custom failure: invalid input (42)')
assert.ok(customErr instanceof Error)
assert.ok(customErr instanceof CustomError)
assert.ok(customErr instanceof FastifyError)

// 3. Plain Error is not an instance of FastifyError
assert.equal(new Error('plain') instanceof FastifyError, false)
assert.equal(genericErr instanceof CustomError, false)

Seeder de origen

anónimo