Skip to content

Class: ConstraintViolationError

@kortexya/reasoninglayer


@kortexya/reasoninglayer / ConstraintViolationError

Defined in: src/errors.ts:202

Constraint violation error (HTTP 409).

A type constraint or uniqueness constraint was violated. Carries structured information about which term, feature, and constraint failed.

A bound constraint whose walk reads data the writer was not shown (a feature that holds a term the caller’s Read grant does not show) refuses a POST /api/v1/terms or PUT /api/v1/terms/{id} with one bare answer (reasoninglayer#1230): ConstraintViolationError.code is constraint_over_unread_data (#1235), the message is The write does not meet a constraint of its sort over data this caller may not read., and the body names no feature, constraint, bound or type. Test for it with isConstraintOverUnreadData, or compare code. Do not test feature === undefined: every 409 without a feature key (a coded conflict, a plain { error, message } body) has no feature either. A constraint over values the writer was shown keeps answering with its named feature and constraint, and no code.

try {
await client.terms.createTerm(request);
} catch (e) {
if (isConstraintOverUnreadData(e)) {
// A constraint over data this caller may not read refused the write.
} else if (e instanceof ConstraintViolationError && e.feature !== undefined) {
console.log(`${e.feature} breaks ${e.constraint}`);
}
}

new ConstraintViolationError(message, body, headers, errorCode?, termId?, feature?, constraint?, code?): ConstraintViolationError

Defined in: src/errors.ts:236

string

unknown

Headers

string

string

string

string

ConstraintViolationCode

ConstraintViolationError

ApiError.constructor

readonly body: unknown

Defined in: src/errors.ts:58

Parsed response body.

ApiError.body


optional cause?: unknown

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26

ApiError.cause


readonly code: ConstraintViolationCode | undefined

Defined in: src/errors.ts:234

The closed code of this refusal: constraint_over_unread_data for the one bare refusal of a bound constraint over data the caller may not read (reasoninglayer#1235); dependants_exceed_commit_budget for a write whose dependants one commit cannot hold (reasoninglayer#1245); dependant_not_writable and dependant_changed_concurrently for the other coded dependant refusals (#1245, #1251); term_changed_concurrently for a read premise another writer broke (#1263); write_targets_derived_fact on a DerivedFactWriteError; write_targets_rule on a RuleTermWriteError. undefined for every other 409; read a code outside ConstraintViolationCode (governed_sort_write_refused, term_id_unavailable, …) with errorBodyCode(error).


readonly component: string | undefined

Defined in: src/errors.ts:52

Health component that produced a structured refusal.

ApiError.component


readonly constraint: string | undefined

Defined in: src/errors.ts:219

The broken constraint in its declared form, the relation CHECK ON writes (paid <= about.credit.limit, reasoninglayer#1262); undefined when the engine names none, as for a bound over data the writer was not shown. Engine d779b31031 and earlier sent a debug rendering (UpperBound { target: "paid", … }).


readonly errorCode: string | undefined

Defined in: src/errors.ts:56

Backend error code (from response body error field), if present.

ApiError.errorCode


readonly feature: string | undefined

Defined in: src/errors.ts:211

Feature name that violated the constraint; undefined when the engine names none, as for a bound over data the writer was not shown.


readonly headers: Headers

Defined in: src/errors.ts:60

Response headers.

ApiError.headers


message: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077

ApiError.message


name: string = 'ConstraintViolationError'

Defined in: src/errors.ts:203

ApiError.name


optional stack?: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078

ApiError.stack


readonly status: number

Defined in: src/errors.ts:54

HTTP status code.

ApiError.status


readonly termId: string | undefined

Defined in: src/errors.ts:206

Term ID that violated the constraint, if available.


static stackTraceLimit: number

Defined in: node_modules/.pnpm/@types+node@24.13.3/node_modules/@types/node/globals.d.ts:68

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

ApiError.stackTraceLimit

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/.pnpm/@types+node@24.13.3/node_modules/@types/node/globals.d.ts:52

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();

object

Function

void

ApiError.captureStackTrace


static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/.pnpm/@types+node@24.13.3/node_modules/@types/node/globals.d.ts:56

Error

CallSite[]

any

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

ApiError.prepareStackTrace