Repository navigation
DF-1509: Convert the form definition error classes to JavaScript with JSDoc - #509
Open
alexluckett wants to merge 1 commit into
Open
alexluckett wants to merge 1 commit into
alexluckett wants to merge 1 commit into
Conversation
SchemaValidationError narrows Error.cause to the Joi ValidationError. JavaScript has no type-only declare field, so a typed class field keeps the value the Error constructor set. As a class field, cause is now enumerable: JSON.stringify(error) includes the validation error, which describes the form definition. The repo logger writes only the error type, message and stack.
alexluckett
force-pushed
the
chore/df-1509-errors
branch
from
November 25, 2026 09:03
2f0943d to
2ee4285
Compare
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Proposed change
Part of the TypeScript to JavaScript migration (v6), this PR is stacked on the public types PR and converts
engine/errors.ts, the form definition error classes, to JavaScript with JSDoc types. It is kept separate because this is the first file where the JavaScript form of an inherited field changes behaviour at runtime.declare cause: ValidationErrornarrows the type ofError.causewithout emitting any code. JavaScript has nodeclare, and a class field without a value would resetcausetoundefinedafter theErrorconstructor has set it. The field therefore takes the value the constructor has already set, with the same comment that is used in the components:cause: ValidationError.Errorstorescauseas a non-enumerable property, whereas a class field is enumerable, socausenow shows up when an error's properties are listed.JSON.stringify(error)will include the Joi validation error, which describes the form definition rather than any data entered by users. This repo's logger (@elastic/ecs-pino-format) writes only the error type, message and stack, and pino's standard serializer skips an error-likecause, so our logs are unaffected.@import Joi from 'joi', and written asJoi.ValidationError. With the braces form,tsc5.9 leaves the import out oferrors.d.tsbecause joi also exportsValidationErroras a value, and the published file would then refer to a type it never imports. Consumers would see that as an error, or asanywithskipLibCheck. A comment in the file explains this, and TypeScript 7 keeps the braces form.conditionName,controllerNameandcomponentTyperemainreadonlyin the published types (@readonly), andpublichas been dropped.The only difference from
mainin the compiled code is thecause = this.causeline. The full test suite gives the same results as onmain(2,583 passed, 13 skipped).Jira ticket: DF-1509
Type of change
Checklist
README.mdanddocs/*(where appropriate, e.g. new features).npm run test).npm run lint).npm run format).