Skip to content

Commit

Permalink
fix(errors): simpler error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Jan 1, 2019
1 parent a3c552a commit 17b83e7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function get(target, key, getter) {

if (context === entry) {
context = null;
throw Error(`[cache] Circular '${key}' get invocation in '${stringifyElement(target)}'`);
throw Error(`Circular '${key}' get invocation in '${stringifyElement(target)}'`);
}

if (context) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export function get(target, key, getter) {
export function set(target, key, setter, value, callback) {
if (context) {
context = null;
throw Error(`[cache] Try to set '${key}' of '${stringifyElement(target)}' in get call`);
throw Error(`Try to set '${key}' of '${stringifyElement(target)}' in get call`);
}

const entry = getEntry(target, key);
Expand All @@ -97,7 +97,7 @@ export function set(target, key, setter, value, callback) {
export function invalidate(target, key, clearValue) {
if (context) {
context = null;
throw Error(`[cache] Try to invalidate '${key}' in '${stringifyElement(target)}' get call`);
throw Error(`Try to invalidate '${key}' in '${stringifyElement(target)}' get call`);
}

const entry = getEntry(target, key);
Expand Down
4 changes: 2 additions & 2 deletions src/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const connects = new WeakMap();
function defineElement(tagName, hybridsOrConstructor) {
const type = typeof hybridsOrConstructor;
if (type !== 'object' && type !== 'function') {
throw TypeError('[define] Invalid second argument. It must be an object or a function');
throw TypeError(`Second argument must be an object or a function: ${type}`);
}

const CustomElement = window.customElements.get(tagName);
Expand Down Expand Up @@ -119,7 +119,7 @@ function defineElement(tagName, hybridsOrConstructor) {
return CustomElement;
}

throw Error(`[define] Element '${tagName}' already defined`);
throw Error(`Element '${tagName}' already defined`);
}

class Hybrid extends HTMLElement {
Expand Down
2 changes: 1 addition & 1 deletion src/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultTransform = v => v;

const objectTransform = (value) => {
if (typeof value !== 'object') {
throw TypeError(`[property] Argument is not an object: ${typeof v}`);
throw TypeError(`Assigned value must be an object: ${typeof v}`);
}
return value && Object.freeze(value);
};
Expand Down
4 changes: 2 additions & 2 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function addToQueue(event) {

export default function render(get, customOptions = {}) {
if (typeof get !== 'function') {
throw TypeError(`[render] The first argument must be a function: ${typeof get}`);
throw TypeError(`The first argument must be a function: ${typeof get}`);
}

const options = { shadowRoot: true, ...customOptions };
Expand All @@ -62,7 +62,7 @@ export default function render(get, customOptions = {}) {
},
connect(host, key) {
if (map.has(host)) {
throw Error(`[render] Render factory already used in '${map.get(host)}' key`);
throw Error(`Render factory already used in '${map.get(host)}' key`);
}

if (options.shadowRoot && !host.shadowRoot) {
Expand Down
2 changes: 1 addition & 1 deletion src/template/resolvers/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const styleMap = new WeakMap();

export default function resolveStyle(host, target, value) {
if (value === null || typeof value !== 'object') {
throw TypeError(`Style value must be an object instance in ${stringifyElement(target)}:`, value);
throw TypeError(`Style value must be an object in ${stringifyElement(target)}:`, value);
}

const previousMap = styleMap.get(target) || new Map();
Expand Down

0 comments on commit 17b83e7

Please # to comment.