From b8f9b93771fdaf317d34c68649b02e84a6d80acc Mon Sep 17 00:00:00 2001 From: jakub Date: Fri, 21 Aug 2020 12:35:07 -0500 Subject: [PATCH 1/3] include tagName when providing bad attr --- lib/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/component.js b/lib/component.js index 6ee26c1d..5961880e 100644 --- a/lib/component.js +++ b/lib/component.js @@ -572,7 +572,7 @@ class Component extends WebComponent { const attrType = attrSchema.type; if (!ATTR_TYPE_DEFAULTS.hasOwnProperty(attrType)) { throw new Error( - `Invalid type: ${attrType} for attr: ${attr} in attrsSchema. ` + + `Invalid type: ${attrType} for attr: ${attr} in ${this.tagName} attrsSchema. ` + `Only (${Object.keys(ATTR_TYPE_DEFAULTS) .map((v) => `'${v}'`) .join(` | `)}) is valid.`, From 6ac52c08d1a00a4ba97a76c897367f065347a074 Mon Sep 17 00:00:00 2001 From: jakub Date: Fri, 21 Aug 2020 13:20:45 -0500 Subject: [PATCH 2/3] include tagName in attrsSchema value error and use _logError for browser debugging --- lib/component.js | 6 ++++-- test/server/component.js | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/component.js b/lib/component.js index 5961880e..923d2d74 100644 --- a/lib/component.js +++ b/lib/component.js @@ -571,8 +571,9 @@ class Component extends WebComponent { // Ensure attr type is valid const attrType = attrSchema.type; if (!ATTR_TYPE_DEFAULTS.hasOwnProperty(attrType)) { + this._logError(`attrsSchema definition error in`, this); throw new Error( - `Invalid type: ${attrType} for attr: ${attr} in ${this.tagName} attrsSchema. ` + + `Invalid type: ${attrType} for attr: ${attr} in ${this.constructor.name} attrsSchema. ` + `Only (${Object.keys(ATTR_TYPE_DEFAULTS) .map((v) => `'${v}'`) .join(` | `)}) is valid.`, @@ -628,8 +629,9 @@ class Component extends WebComponent { const enumSet = attrSchema.enumSet; if (enumSet && !enumSet.has(attrValue)) { + this._logError(`attrsSchema value error in`, this); throw new Error( - `Invalid value: '${attrValue}' for attr: ${attr}. ` + + `Invalid value: '${attrValue}' for attr: ${attr} in element ${this.tagName}. ` + `Only (${Array.from(enumSet) .map((v) => `'${v}'`) .join(` | `)}) is valid.`, diff --git a/test/server/component.js b/test/server/component.js index d79ae09d..171943a3 100644 --- a/test/server/component.js +++ b/test/server/component.js @@ -186,16 +186,17 @@ describe(`Server-side component renderer`, function () { }); it(`throws error for invalid value in an enum attr`, function () { - const el = new AttrsReflectionApp(); + const el = document.createElement(`attrs-reflection-app`); + el.connectedCallback(); expect(() => el.setAttribute(`str-attr`, `boo!`)).to.throw( - `Invalid value: 'boo!' for attr: str-attr. Only ('hello' | 'world' | '💩🤒🤢☠️ -> 👻🎉💐🎊😱😍') is valid.`, + `Invalid value: 'boo!' for attr: str-attr in element attrs-reflection-app. Only ('hello' | 'world' | '💩🤒🤢☠️ -> 👻🎉💐🎊😱😍') is valid.`, ); }); it(`throws error if there is a malformed attrsSchema type`, function () { expect(() => new BadAttrsSchemaApp()).to.throw( - `Invalid type: bool for attr: bad-attr in attrsSchema. Only ('string' | 'boolean' | 'number' | 'json') is valid.`, + `Invalid type: bool for attr: bad-attr in BadAttrsSchemaApp attrsSchema. Only ('string' | 'boolean' | 'number' | 'json') is valid.`, ); }); }); From 537c712231648094a0a45e049f5b4d75cb9e901f Mon Sep 17 00:00:00 2001 From: jakub Date: Fri, 21 Aug 2020 13:57:53 -0500 Subject: [PATCH 3/3] remove the _logError for invalid attr type --- lib/component.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/component.js b/lib/component.js index 923d2d74..4ce3b901 100644 --- a/lib/component.js +++ b/lib/component.js @@ -571,7 +571,6 @@ class Component extends WebComponent { // Ensure attr type is valid const attrType = attrSchema.type; if (!ATTR_TYPE_DEFAULTS.hasOwnProperty(attrType)) { - this._logError(`attrsSchema definition error in`, this); throw new Error( `Invalid type: ${attrType} for attr: ${attr} in ${this.constructor.name} attrsSchema. ` + `Only (${Object.keys(ATTR_TYPE_DEFAULTS)