サンプル
tinyexec 1.3.0: NonZeroExitError
検証済みサンプル — npm tinyexec 1.3.0: NonZeroExitError. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: NonZeroExitError is an Error subclass…
sha256:72b59841986713e9c5eff359f36e9ec3254a95ff24d73fc4c29a157e31bb0a71
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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-06 |
ケース
HOW- ゴール
- verify tinyexec.NonZeroExitError in pkg:npm/tinyexec@1.3.0
- パッケージ
- シンボル
-
- tinyexec.NonZeroExitError
- 環境
- node 22.23.2
- 作成日
- 2026-09-06T14:42:53Z
コントラクト
- NonZeroExitError is an Error subclass representing command exit failure
- NonZeroExitError constructor populates exitCode, signalCode, output, and non-enumerable result
- NonZeroExitError formats error message with command and arguments on non-zero exit
- NonZeroExitError formats error message with termination signal when process is killed
- x throws NonZeroExitError containing stdout, stderr, and exitCode when throwOnError is enabled
- xSync throws NonZeroExitError containing output and exitCode when throwOnError is enabled
- ExecProcess async iteration throws NonZeroExitError when process terminates with non-zero exit code
- NonZeroExitError signalCode captures process signal when process is killed with throwOnError enabled
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
ソース
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 tinyexec.NonZeroExitError in pkg:npm/tinyexec@1.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/tinyexec@1.3.0
Demonstrate these symbols/APIs:
- tinyexec.NonZeroExitError
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.
{"case":{"caseId":"case:sha256:c4c1b270cab4700de29b180fb76b7423b339c1f5d220f6cec080021cf61a815a","contract":["NonZeroExitError is an Error subclass representing command exit failure","NonZeroExitError constructor populates exitCode, signalCode, output, and non-enumerable result","NonZeroExitError formats error message with command and arguments on non-zero exit","NonZeroExitError formats error message with termination signal when process is killed","x throws NonZeroExitError containing stdout, stderr, and exitCode when throwOnError is enabled","xSync throws NonZeroExitError containing output and exitCode when throwOnError is enabled","ExecProcess async iteration throws NonZeroExitError when process terminates with non-zero exit code","NonZeroExitError signalCode captures process signal when process is killed with throwOnError enabled"],"goal":"verify tinyexec.NonZeroExitError in pkg:npm/tinyexec@1.3.0","kind":"HOW","packages":["pkg:npm/tinyexec@1.3.0"],"schemaVersion":1,"symbols":["tinyexec.NonZeroExitError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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/tinyexec@1.3.0"],"schemaVersion":1,"subject":"pkg:npm/tinyexec@1.3.0","symbols":["tinyexec.NonZeroExitError"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-tinyexec-nonzeroexiterror",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-tinyexec-nonzeroexiterror",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"tinyexec": "1.3.0"
}
},
"node_modules/tinyexec": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.0.tgz",
"integrity": "sha512-QKAl9m8gWWGHV8jZcPeym6j+XULi6tOf1mT83WYJ4Lk2ytW/uwAWkrP0uFsdoYMdueVJ0qs26wZ+23xeB4ibNQ==",
"license": "MIT",
"engines": {
"node": ">=18"
}
}
}
}
{
"name": "sample-tinyexec-nonzeroexiterror",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of tinyexec.NonZeroExitError in pkg:npm/tinyexec@1.3.0",
"type": "module",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"tinyexec": "1.3.0"
}
}
{
"schemaVersion": 1,
"goal": "verify tinyexec.NonZeroExitError in pkg:npm/tinyexec@1.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/tinyexec@1.3.0"
],
"symbols": [
"tinyexec.NonZeroExitError"
]
}
import { NonZeroExitError, x, xSync, ExecProcess } from 'tinyexec';
/**
* Creates a NonZeroExitError instance.
* @param {import('tinyexec').CommonOutputApi} result - Execution output API instance
* @param {import('tinyexec').Output} [output] - Output object with stdout, stderr, exitCode
* @param {string} [command] - Command name
* @param {string[]} [args] - Command arguments
* @returns {NonZeroExitError}
*/
export function createNonZeroExitError(result, output, command, args) {
return new NonZeroExitError(result, output, command, args);
}
/**
* Executes a command asynchronously with throwOnError enabled.
* @param {string} command - Command to run
* @param {string[]} [args] - Arguments
* @param {object} [options] - Options
* @returns {import('tinyexec').Result}
*/
export function runWithThrowOnError(command, args, options) {
return x(command, args, { ...options, throwOnError: true });
}
/**
* Executes a command synchronously with throwOnError enabled.
* @param {string} command - Command to run
* @param {string[]} [args] - Arguments
* @param {object} [options] - Options
* @returns {import('tinyexec').SyncResult}
*/
export function runSyncWithThrowOnError(command, args, options) {
return xSync(command, args, { ...options, throwOnError: true });
}
export { NonZeroExitError, x, xSync, ExecProcess };
import assert from 'node:assert/strict';
import {
NonZeroExitError,
x,
xSync,
ExecProcess,
createNonZeroExitError,
runWithThrowOnError,
runSyncWithThrowOnError
} from '../src/index.js';
// 1. NonZeroExitError is an Error subclass representing command exit failure
assert.equal(typeof NonZeroExitError, 'function', 'NonZeroExitError must be a constructor function');
assert.ok(NonZeroExitError.prototype instanceof Error, 'NonZeroExitError must extend Error');
assert.equal(typeof createNonZeroExitError, 'function');
assert.equal(typeof runWithThrowOnError, 'function');
assert.equal(typeof runSyncWithThrowOnError, 'function');
// 2. NonZeroExitError constructor populates exitCode, signalCode, output, and non-enumerable result
{
const mockResult = {
exitCode: 42,
signalCode: null,
pid: 1234,
killed: false
};
const mockOutput = {
stdout: 'mock stdout',
stderr: 'mock stderr',
exitCode: 42
};
const err = createNonZeroExitError(mockResult, mockOutput, 'my-cmd', ['--flag', 'value with spaces']);
assert.ok(err instanceof Error);
assert.ok(err instanceof NonZeroExitError);
assert.equal(err.exitCode, 42);
assert.equal(err.signalCode, null);
assert.deepEqual(err.output, mockOutput);
assert.equal(err.result, mockResult);
assert.equal(Object.prototype.propertyIsEnumerable.call(err, 'result'), false);
}
// 3. NonZeroExitError formats error message with command and arguments on non-zero exit
{
const mockResult = {
exitCode: 2,
signalCode: null,
pid: 2222,
killed: false
};
const errWithArgs = createNonZeroExitError(mockResult, undefined, 'test-bin', ['arg1', 'arg with space']);
assert.equal(errWithArgs.message, 'The command `test-bin arg1 "arg with space"` exited with a non-zero status (2)');
const errNoCommand = createNonZeroExitError(mockResult);
assert.equal(errNoCommand.message, 'The process exited with a non-zero status (2)');
}
// 4. NonZeroExitError formats error message with termination signal when process is killed
{
const mockResult = {
exitCode: null,
signalCode: 'SIGKILL',
pid: 3333,
killed: true
};
const err = createNonZeroExitError(mockResult, undefined, 'long-runner');
assert.equal(err.signalCode, 'SIGKILL');
assert.equal(err.exitCode, 1);
assert.equal(err.message, 'The command `long-runner` was killed by the signal SIGKILL');
}
// 5. x throws NonZeroExitError containing stdout, stderr, and exitCode when throwOnError is enabled
{
await assert.rejects(
async () => {
await runWithThrowOnError('node', [
'-e',
'process.stdout.write("standard message\\n"); process.stderr.write("error message\\n"); process.exit(7);'
]);
},
(err) => {
assert.ok(err instanceof NonZeroExitError, 'Expected instance of NonZeroExitError');
assert.equal(err.exitCode, 7);
assert.equal(err.signalCode, null);
assert.equal(err.output?.stdout, 'standard message\n');
assert.equal(err.output?.stderr, 'error message\n');
assert.equal(err.output?.exitCode, 7);
return true;
}
);
}
// 6. xSync throws NonZeroExitError containing output and exitCode when throwOnError is enabled
{
assert.throws(
() => {
runSyncWithThrowOnError('node', [
'-e',
'process.stdout.write("sync stdout\\n"); process.stderr.write("sync stderr\\n"); process.exit(9);'
]);
},
(err) => {
assert.ok(err instanceof NonZeroExitError, 'Expected instance of NonZeroExitError');
assert.equal(err.exitCode, 9);
assert.equal(err.signalCode, null);
assert.equal(err.output?.stdout, 'sync stdout\n');
assert.equal(err.output?.stderr, 'sync stderr\n');
assert.equal(err.output?.exitCode, 9);
return true;
}
);
}
// 7. ExecProcess async iteration throws NonZeroExitError when process terminates with non-zero exit code
{
const proc = new ExecProcess(
'node',
['-e', 'console.log("line-one"); console.log("line-two"); process.exit(11);'],
{ throwOnError: true }
);
proc.spawn();
const receivedLines = [];
await assert.rejects(
async () => {
for await (const line of proc) {
receivedLines.push(line.trim());
}
},
(err) => {
assert.ok(err instanceof NonZeroExitError, 'Expected instance of NonZeroExitError');
assert.equal(err.exitCode, 11);
return true;
}
);
assert.deepEqual(receivedLines, ['line-one', 'line-two']);
}
// 8. NonZeroExitError signalCode captures process signal when process is killed with throwOnError enabled
{
await assert.rejects(
async () => {
const proc = runWithThrowOnError('node', ['-e', 'setInterval(() => {}, 1000);']);
await new Promise((resolve) => setTimeout(resolve, 50));
proc.kill('SIGTERM');
await proc;
},
(err) => {
assert.ok(err instanceof NonZeroExitError, 'Expected instance of NonZeroExitError');
assert.equal(err.signalCode, 'SIGTERM');
assert.ok(err.message.includes('was killed by the signal SIGTERM'));
return true;
}
);
}
console.log('All contract assertions passed.');
オリジンシーダー
匿名