Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved error messages for cloud- or oss-only commands #140

Merged
merged 5 commits into from
Jun 23, 2021

Conversation

williamhbaker
Copy link
Contributor

@williamhbaker williamhbaker commented Jun 23, 2021

Closes #129

Note for future readers: As the review discussion indicates, we ended up only implementing chaining the OnlyOSS()/OnlyCloud() methods off of API services, rather than individual requests. The original PR description is below in its entirety for reference.

This PR adds the ability to set properties on individual API requests or all requests in a particular API service by chaining methods called OnlyOSS() or OnlyCloud() when the requests or services are created. I also tweaked the generic "undefined response type" output to be a little more descriptive.

If the request fails, the resulting error will be changed from something like this:

influx ping
Error: undefined response type

...to something like this:

influx ping
Error: InfluxDB OSS-only command failed: unable to decode response content type "text/html"

As part of this, I set BackupApi and RestoreApi to be "OnlyOSS", and the GetHealth request of the Ping command to be "OnlyOSS" as well. We could set the entire HealthApi to be "OnlyOSS" - I did this for demonstration purposes more than anything...and there is actually a working /ping endpoint on cloud so maybe we'll want to use that someday.

For cloud-only endpoints, the BucketsSchemaApi was set to "OnlyCloud", which changes the error message when trying to use the command on an OSS server:

influx bucket-schema list -n bucket
Error: failed to list measurement schemas: undefined response type

...becomes:

influx bucket-schema list -n bucket
Error: failed to list measurement schemas: InfluxDB Cloud-only command failed: unable to decode response content type "text/plain; charset=utf-8"

Future work, which is currently blocked by influxdata/influxdb#20224 (& the equivalent cloud issue), could explicitly check the X-Influxdb-Version based on these properties and return a more specific error message. This could even include a pre-flight check of some kind to make sure the server supports the command if they are flagged as being cloud- or oss-only before trying to execute the requests. I'll create an additional issue to document this further work when we merge this PR.

func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request) OnlyCloud() {{#structPrefix}}{{&classname}}{{/structPrefix}}Api{{operationId}}Request {
r.isOnlyCloud = true
return r
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd vote to keep things simple for now and have the OSS-vs-Cloud toggle at the API level, and not per-request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Should make it easier to keep track of what has been flagged for a specific server type for sure.

api/templates/api.mustache Outdated Show resolved Hide resolved
@williamhbaker williamhbaker force-pushed the wb-improved-errs-129 branch from 38b6293 to 712edc7 Compare June 23, 2021 14:03
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.

CLI: Improve error messaging when an unexpected response comes back
2 participants