Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/core/src/util/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ import { isOneOfEnumSchema } from './schema';
import filter from 'lodash/filter';
import isEqual from 'lodash/isEqual';

/**
* Checks for an additionally specified property that the error relates to.
* This may be added to an error's instancePath to show it add the violating property's control.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "to show it add the violating" should be "to show it at the violating".

* For example, for required property errors, the instancePath points to the object containing the required property.
* The missing property's name is specified in the error's params.missingProperty field and returned by this function.
*
* @param error The ErrorObject to check for an additionally specified property that the error relates to
* @returns The invalid property name if present, otherwise undefined
*/
const getInvalidProperty = (error: ErrorObject): string | undefined => {
switch (error.keyword) {
case 'required':
Expand All @@ -51,12 +60,12 @@ export const getControlPath = (error: ErrorObject) => {
controlPath = controlPath.replace(/\//g, '.');

const invalidProperty = getInvalidProperty(error);
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
if (invalidProperty !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we originally added the endsWith check? There must have been a reason

controlPath = `${controlPath}.${invalidProperty}`;
}

// remove '.' chars at the beginning of paths
controlPath = controlPath.replace(/^./, '');
controlPath = controlPath.replace(/^\./, '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍


// decode JSON Pointer escape sequences
controlPath = decode(controlPath);
Expand Down
Loading