Class: ConstraintViolationError
@kortexya/reasoninglayer / ConstraintViolationError
Class: ConstraintViolationError
Section titled “Class: 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.
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”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}`); }}Extends
Section titled “Extends”Extended by
Section titled “Extended by”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ConstraintViolationError(
message,body,headers,errorCode?,termId?,feature?,constraint?,code?):ConstraintViolationError
Defined in: src/errors.ts:236
Parameters
Section titled “Parameters”message
Section titled “message”string
unknown
headers
Section titled “headers”Headers
errorCode?
Section titled “errorCode?”string
termId?
Section titled “termId?”string
feature?
Section titled “feature?”string
constraint?
Section titled “constraint?”string
Returns
Section titled “Returns”ConstraintViolationError
Overrides
Section titled “Overrides”Properties
Section titled “Properties”
readonlybody:unknown
Defined in: src/errors.ts:58
Parsed response body.
Inherited from
Section titled “Inherited from”cause?
Section titled “cause?”
optionalcause?:unknown
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
Inherited from
Section titled “Inherited from”
readonlycode: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).
component
Section titled “component”
readonlycomponent:string|undefined
Defined in: src/errors.ts:52
Health component that produced a structured refusal.
Inherited from
Section titled “Inherited from”constraint
Section titled “constraint”
readonlyconstraint: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", … }).
errorCode
Section titled “errorCode”
readonlyerrorCode:string|undefined
Defined in: src/errors.ts:56
Backend error code (from response body error field), if present.
Inherited from
Section titled “Inherited from”feature
Section titled “feature”
readonlyfeature: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.
headers
Section titled “headers”
readonlyheaders:Headers
Defined in: src/errors.ts:60
Response headers.
Inherited from
Section titled “Inherited from”message
Section titled “message”message:
string
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077
Inherited from
Section titled “Inherited from”name:
string='ConstraintViolationError'
Defined in: src/errors.ts:203
Overrides
Section titled “Overrides”stack?
Section titled “stack?”
optionalstack?:string
Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078
Inherited from
Section titled “Inherited from”status
Section titled “status”
readonlystatus:number
Defined in: src/errors.ts:54
HTTP status code.
Inherited from
Section titled “Inherited from”termId
Section titled “termId”
readonlytermId:string|undefined
Defined in: src/errors.ts:206
Term ID that violated the constraint, if available.
stackTraceLimit
Section titled “stackTraceLimit”
staticstackTraceLimit: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.
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”captureStackTrace()
Section titled “captureStackTrace()”
staticcaptureStackTrace(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();Parameters
Section titled “Parameters”targetObject
Section titled “targetObject”object
constructorOpt?
Section titled “constructorOpt?”Function
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”prepareStackTrace()
Section titled “prepareStackTrace()”
staticprepareStackTrace(err,stackTraces):any
Defined in: node_modules/.pnpm/@types+node@24.13.3/node_modules/@types/node/globals.d.ts:56
Parameters
Section titled “Parameters”Error
stackTraces
Section titled “stackTraces”CallSite[]
Returns
Section titled “Returns”any
https://v8.dev/docs/stack-trace-api#customizing-stack-traces