Skip to content

Commit

Permalink
skip image if validation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Nov 27, 2019
1 parent bfb1dbe commit 40e86d3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/render/image_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,26 @@ class ImageManager extends Evented {
}

addImage(id: string, image: StyleImage) {
this._validate(id, image);
assert(!this.images[id]);
this.images[id] = image;
if (this._validate(id, image)) {
this.images[id] = image;
}
}

_validate(id: string, image: StyleImage) {
if (!this._validateStretch(image.stretchX, image.data && image.data.width)) {
this.fire(new ErrorEvent(new Error(`Image "${id}" has invalid "stretchX" value`)));
return false;
}
if (!this._validateStretch(image.stretchY, image.data && image.data.height)) {
this.fire(new ErrorEvent(new Error(`Image "${id}" has invalid "stretchY" value`)));
return false;
}
if (!this._validateContent(image.content, image)) {
this.fire(new ErrorEvent(new Error(`Image "${id}" has invalid "content" value`)));
return false;
}
return true;
}

_validateStretch(stretch: ?Array<[number, number]> | void, size: number) {
Expand Down

2 comments on commit 40e86d3

@ahk
Copy link
Contributor

@ahk ahk commented on 40e86d3 Nov 27, 2019

Choose a reason for hiding this comment

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

Sorry, last request: could we allow all errors to fire and return validation status at the end? Validation looks like it's incredibly cheap so probably better to let the user see all the problems rather than short-circuit them.

@ansis
Copy link
Contributor Author

@ansis ansis commented on 40e86d3 Nov 27, 2019

Choose a reason for hiding this comment

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

@ahk changed in 3e4e2ae

Please sign in to comment.