Skip to content

Adding parameter feedback - #239

Merged
Dynom merged 4 commits into
h2non:masterfrom
Dynom:RefactoringParameterParsingToImproveFeedback
Jan 20, 2019
Merged

Dynom merged 4 commits into
h2non:masterfrom
Dynom:RefactoringParameterParsingToImproveFeedback

Conversation

@Dynom

@Dynom Dynom commented Jan 19, 2019 •

Copy link
Copy Markdown
Collaborator

Warning. Here be (albeit tiny) dragons.

I've spent a quite a while trying to simplify the parameter handling. It was rather complicated to grasp since there were two pretty different cases: The Pipeline and the HTTP parameter handling.

I've, eventually, came up with a pretty radical rewrite of the parameter handling. There is quite a bit of boilerplate, but (imho) it's now much simpler to deal with parameters and much less passing around of interface{} types.

There aren't breaking API changes. In some cases it wasn't allowed to pass in a string where a number was expected (e.g.: {"width": 200} versus {"width": "200"}). In the new situation that is allowed. While I'm not necessarily a fan of allowing strings where numbers are "correct", this is a side-effect of how the parse<T>() functions are implemented. It's more generic (HTTP parameter versus JSON types) and hopefully easier to understand.

There is also slightly more information when the user does pass in a wrong parameter, e.g.:

curl -sv "http://localhost:9000/pipeline?url=https://pbs.twimg.com/media/DwX-vRdUYAACZ0x.jpg&operations=%5B%7B%22operation%22%3A%22resize%22%2C%22params%22%3A%7B%22quality%22%3A70%2C%22noprofile%22%3Atrue%2C%22stripmeta%22%3Atrue%2C%22nocrop%22%3A%22foo%22%2C%22width%22%3A865%7D%7D%5D"
{
  "message": "Error while processing the image: error while processing parameter \"nocrop\" with value \"foo\", error: unsupported value",
  "code": 1
}

Inspired by issues #236 and #233

Breaking Pre-Go1.10 compatibility

I've added the new (since Go 1.10) flag DisallowUnknownFields() on the JSON decoder. This causes Imaginary to be >= Go 1.10. Personally I think it's fine, but if this is a problem I can drop the flag and this way we'll support older Go versions.

@Dynom
Dynom requested a review from h2non January 19, 2019 23:00
@Dynom Dynom self-assigned this Jan 19, 2019
@h2non

h2non commented Jan 20, 2019

Copy link
Copy Markdown
Owner

Thanks for taking time & care of this.

I guess I'm fine with the DisallowUnknownFields() usage, according to Postel's Law principle. Also, there is no huge pain in Go ecosystem when running older versions, and people tend to upgrade easily because of the great non-breaking changes updates, so no biggie here.

We should, however, remove Go <= 1.9 Travis CI builds and make it clear in the README that the minimum supported version is Go 1.10.

@h2non h2non left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Overall, LGTM. The parsing approach is mor solid and opens the possibility to more fine-grained a validation and error reporting.

Comment thread .travis.yml Outdated
- env: LIBVIPS=8.3
- env: LIBVIPS=master
- go: 1.8.x
- go: 1.9.x

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's just use Go 1.10.

@h2non

h2non commented Jan 20, 2019

Copy link
Copy Markdown
Owner

Feel free to merge when ready, bump patch version and publish a new release.

@Dynom
Dynom merged commit 8ae6483 into h2non:master Jan 20, 2019
@Dynom
Dynom deleted the RefactoringParameterParsingToImproveFeedback branch January 20, 2019 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址