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

More informative error messages #1056

Merged
merged 7 commits into from
Jul 9, 2019
Merged

Conversation

maxalbert
Copy link
Contributor

Closes #1055

I have:

  • Formatted any Python files with black
  • Brought the branch up to date with master
  • Added any relevant Github labels
  • Added tests for any new additions
  • Added or updated any relevant documentation
  • Added an Architectural Decision Record (ADR), if appropriate
  • Added an MPLv2 License Header if appropriate
  • Updated the Changelog

Description

This PR improves the error messages returned from flowmachine when query parameter validation fails. The message now includes the parameters which failed to validate, and prints them in a more readable way on the command line.

It also adds an explicit else clause in a helper function, to avoid random errors caused by the fact that spatial_unit_args is potentially undefined.

Previous error message:

flowclient.client.FlowclientConnectionError: Something went wrong. API returned with status code 400. Error message: 'Parameter validation failed.'. Payload: {'0': {'locations': {'0': {'aggregation_unit': ['Must be one of: admin0, admin1, admin2, admin3.']}}, 'metric': {'0': {'reference_location': {'0': {'aggregation_unit': ['Must be one of: admin0, admin1, admin2, admin3.']}}}}}}

New error message:

E           flowclient.client.FlowclientConnectionError: Something went wrong. API returned with status code 400. Error message: 'Parameter validation failed.
E           
E           The action parameters were:
E              {
E                "query_kind": "joined_spatial_aggregate",
E                "method": "avg",
E                "locations": {
E                  "query_kind": "daily_location",
E                  "date": "2016-01-01",
E                  "aggregation_unit": "lon-lat",
E                  "method": "last",
E                  "subscriber_subset": null
E                },
E                "metric": {
E                  "query_kind": "displacement",
E                  "start": "2016-01-01",
E                  "stop": "2016-01-02",
E                  "value": "avg",
E                  "reference_location": {
E                    "query_kind": "daily_location",
E                    "date": "2016-01-01",
E                    "aggregation_unit": "lon-lat",
E                    "method": "last",
E                    "subscriber_subset": null
E                  },
E                  "subscriber_subset": null
E                }
E              }.
E           
E           Validation error messages:
E              {
E                "0": {
E                  "metric": {
E                    "0": {
E                      "reference_location": {
E                        "0": {
E                          "aggregation_unit": [
E                            "Must be one of: admin0, admin1, admin2, admin3."
E                          ]
E                        }
E                      }
E                    }
E                  },
E                  "locations": {
E                    "0": {
E                      "aggregation_unit": [
E                        "Must be one of: admin0, admin1, admin2, admin3."
E                      ]
E                    }
E                  }
E                }
E              }.
E           
E           '.

../flowclient/flowclient/client.py:196: FlowclientConnectionError

Maximilian Albert added 3 commits July 9, 2019 11:46
…. Also, pretty-print the parameters and validation errors to make errors easier to parse.
@maxalbert maxalbert added FlowMachine Issues related to FlowMachine FlowAPI Issues related to the FlowKit API development labels Jul 9, 2019
@codecov
Copy link

codecov bot commented Jul 9, 2019

Codecov Report

Merging #1056 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1056      +/-   ##
==========================================
+ Coverage   93.92%   94.03%   +0.11%     
==========================================
  Files         142      144       +2     
  Lines        6911     7030     +119     
  Branches      688      694       +6     
==========================================
+ Hits         6491     6611     +120     
  Misses        309      309              
+ Partials      111      110       -1
Flag Coverage Δ
#flowapi_unit_tests 82.4% <ø> (ø) ⬆️
#flowauth_unit_tests 94.86% <ø> (ø) ⬆️
#flowclient_unit_tests 80.9% <100%> (+0.08%) ⬆️
#flowetl_unit_tests 100% <ø> (ø) ⬆️
#flowkit_jwt_generator_unit_tests 100% <ø> (?)
#flowmachine_unit_tests 91.11% <37.5%> (-0.03%) ⬇️
#integration_tests 63.45% <70%> (+0.04%) ⬆️
Impacted Files Coverage Δ
flowclient/flowclient/client.py 94.54% <100%> (+0.02%) ⬆️
...hine/core/server/query_schemas/aggregation_unit.py 100% <100%> (+7.14%) ⬆️
...machine/flowmachine/core/server/action_handlers.py 93.52% <100%> (+0.24%) ⬆️
flowkit_jwt_generator/flowkit_jwt_generator/jwt.py 100% <0%> (ø)
...it_jwt_generator/flowkit_jwt_generator/fixtures.py 100% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0536e4...2eb1188. Read the comment docs.

Copy link
Contributor

@BhavinPanch BhavinPanch left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@maxalbert maxalbert added the ready-to-merge Label indicating a PR is OK to automerge label Jul 9, 2019
@mergify mergify bot merged commit 374a2d8 into master Jul 9, 2019
@mergify mergify bot deleted the more-informative-error-messages branch July 9, 2019 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development FlowAPI Issues related to the FlowKit API FlowMachine Issues related to FlowMachine ready-to-merge Label indicating a PR is OK to automerge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validation errors returned via flowapi are difficult to debug
2 participants