CodeSampleX

Пример

@fastify/error 4.2.0: FastifyError

Проверенный пример — npm @fastify/error 4.2.0: FastifyError. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.

sha256:19bb209ba17303f3565f9f2311c7d7781414412f6b1c7bd914d86e0adf5813c7

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
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

Кейс

HOW
Цель
verify @fastify/error.FastifyError in pkg:npm/%40fastify/error@4.2.0
Пакеты
Символы
  • @fastify/error.FastifyError
Создан
2026-10-20T14:05:50Z

Контракт

  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

Файлы

  • PROMPT.md
  • csx.json
  • 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 @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)

Исходный сидер

аноним