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: error-doc handling in python SDK #1440

Merged
merged 3 commits into from
Mar 8, 2024
Merged

Conversation

drstrangelooker
Copy link
Collaborator

@drstrangelooker drstrangelooker commented Mar 8, 2024

Lookups now take place against the CDN to find a more detailed error guide. The url to that error guide, and the error guide itself - a markdown document - are included in the SDKError class and the ErrorDetail class.

@drstrangelooker drstrangelooker requested a review from a team as a code owner March 8, 2024 16:28
@drstrangelooker
Copy link
Collaborator Author

Sample output after adding some prints to test_connection.py

$ PYTHONPATH=~/sdk-codegen/python python test_connection.py foo
/usr/local/google/home/drstrangelove/.pyenv/versions/3.8.2/lib/python3.8/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
/usr/local/google/home/drstrangelove/.pyenv/versions/3.8.2/lib/python3.8/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
https://static-a.cdn.looker.app/errorcodes/404.md
## HTTP Status Code 404 - Not Found

## Description

A 404 Not Found error is the default error if anything goes wrong, usually with things like permissions. The response message for a 404 error provides minimal, if any, information. This is intentional, since 404 errors are shown to people with incorrect login credentials or insufficient permissions. Looker does not want to provide specific information in 404 response messages, since this information could be used to map out the "attack surface" of our API.

If API `/login` attempts are returning 404 errors, it's most likely because your API3 `client_id` or `client_secret` isn't valid (see [this section](https://docs.looker.com/reference/api-and-integration/api-troubleshooting#verify_your_api_credentials) of our API troubleshooting doc). The API login REST endpoint is one of the following, depending on the API version in use:

`https://<your-looker-hostname>:<port>/api/4.0/login`
`https://<your-looker-hostname>:<port>/api/3.1/login`

You can also get a 404 error after you log in. If you're logged in and you get a 404 error, that means you don't have permissions for the API command you just called.

## Resolution

* For a Swagger codegen client, the `base_url` should be one of the following, depending on the API version in use:
`https://<your-looker-hostname>:<port>/api/4.0/`
`https://<your-looker-hostname>:<port>/api/3.1/`

* If login is successful, verify that the logged in user has permissions to execute the given command in the UI.

## Reference

See the [Mozilla website](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404) for more information on HTTP status code 404

See [Looker API Troubleshooting](https://cloud.google.com/looker/docs/reference/api-and-integration/api-troubleshooting) for more information on troubleshooting API errors in Looker
[]
Traceback (most recent call last):
  File "test_connection.py", line 80, in <module>
    main()
  File "test_connection.py", line 39, in main
    raise e
  File "test_connection.py", line 34, in main
    connection = get_connections(connection_name)
  File "test_connection.py", line 47, in get_connections
    connection = sdk.connection(name, fields="name, dialect")
  File "/usr/local/google/home/drstrangelove/sdk-codegen/python/looker_sdk/sdk/api40/methods.py", line 3534, in connection
    self.get(
  File "/usr/local/google/home/drstrangelove/sdk-codegen/python/looker_sdk/rtl/api_methods.py", line 157, in get
    return self._return(response, structure)
  File "/usr/local/google/home/drstrangelove/sdk-codegen/python/looker_sdk/rtl/api_methods.py", line 101, in _return
    raise sdk_error
looker_sdk.error.SDKError

Copy link
Contributor

github-actions bot commented Mar 8, 2024

Python Tests

    9 files      9 suites   1m 46s ⏱️
144 tests 139 ✔️   5 💤 0 ❌
676 runs  657 ✔️ 19 💤 0 ❌

Results for commit a80f140.

@drstrangelooker
Copy link
Collaborator Author

Updated the SDKError and ErrorDoc objects with a __str__() method so that they automagically display some useful data.

looker_sdk.error.SDKError: 
    message:           Not found
    documentation_url: https://cloud.google.com/looker/docs/r/err/4.0/404/get/connections/:connection_name
    error_doc_url:     https://static-a.cdn.looker.app/errorcodes/404.md
    error details:

Copy link
Contributor

github-actions bot commented Mar 8, 2024

Python Tests

    9 files      9 suites   1m 58s ⏱️
144 tests 139 ✔️   5 💤 0 ❌
676 runs  657 ✔️ 19 💤 0 ❌

Results for commit e264d2d.

@drstrangelooker drstrangelooker requested a review from jkaster March 8, 2024 19:36
Copy link
Contributor

github-actions bot commented Mar 8, 2024

Python Tests

    8 files      8 suites   1m 19s ⏱️
144 tests 138 ✔️   5 💤 0 ❌ 1 🔥
653 runs  634 ✔️ 18 💤 0 ❌ 1 🔥

For more details on these errors, see this check.

Results for commit e89193c.

Copy link
Contributor

github-actions bot commented Mar 8, 2024

Python Tests

    9 files      9 suites   1m 45s ⏱️
144 tests 139 ✔️   5 💤 0 ❌
676 runs  657 ✔️ 19 💤 0 ❌

Results for commit e89193c.

Copy link
Contributor

@jkaster jkaster left a comment

Choose a reason for hiding this comment

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

This is a slightly different implementation than we have for other SDKs due to needing to keep SDKs like TS as lean as possible, but this feels like it could be a good approach for the Python SDK, and perhaps some of the others. Will consider it for other SDK implementations.

@drstrangelooker drstrangelooker merged commit 21daada into main Mar 8, 2024
24 checks passed
@drstrangelooker drstrangelooker deleted the python-error-doc branch March 8, 2024 22:10

This comment has been minimized.

drstrangelooker pushed a commit that referenced this pull request Mar 13, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>@looker/api-explorer: 0.9.58</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-utils bumped from 0.1.34 to 0.1.35
    * @looker/run-it bumped from 0.9.57 to 0.9.58
    * @looker/sdk bumped from 24.2.0 to 24.2.1
  * devDependencies
    * @looker/sdk-codegen-scripts bumped from 21.5.14 to 21.5.15
    * @looker/sdk-node bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/extension-api-explorer: 22.21.15</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/api-explorer bumped from 0.9.57 to 0.9.58
    * @looker/extension-sdk bumped from 24.2.0 to 24.2.1
    * @looker/extension-sdk-react bumped from 24.2.0 to 24.2.1
    * @looker/extension-utils bumped from 0.1.34 to 0.1.35
    * @looker/run-it bumped from 0.9.57 to 0.9.58
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/extension-playground: 1.0.15</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from 24.2.0 to 24.2.1
    * @looker/extension-sdk-react bumped from 24.2.0 to 24.2.1
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/extension-tile-playground: 1.1.2</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from 24.2.0 to 24.2.1
    * @looker/extension-sdk-react bumped from 24.2.0 to 24.2.1
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/extension-utils: 0.1.35</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from 24.2.0 to 24.2.1
    * @looker/extension-sdk-react bumped from 24.2.0 to 24.2.1
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/hackathon: 22.21.17</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from 24.2.0 to 24.2.1
    * @looker/extension-sdk-react bumped from 24.2.0 to 24.2.1
    * @looker/extension-utils bumped from 0.1.34 to 0.1.35
    * @looker/sdk bumped from 24.2.0 to 24.2.1
    * @looker/wholly-artifact bumped from 0.1.15 to 0.1.16
</details>

<details><summary>@looker/run-it: 0.9.58</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-utils bumped from 0.1.34 to 0.1.35
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/sdk-codegen-scripts: 21.5.15</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from 24.2.0 to 24.2.1
    * @looker/sdk-node bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/wholly-artifact: 0.1.16</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from 24.2.0 to 24.2.1
  * devDependencies
    * @looker/sdk-node bumped from 24.2.0 to 24.2.1
</details>

<details><summary>@looker/wholly-sheet: 0.5.54</summary>

### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from 24.2.0 to 24.2.1
  * devDependencies
    * @looker/sdk-node bumped from 24.2.0 to 24.2.1
</details>

<details><summary>sdk-codegen-all: 24.3.0</summary>

##
[24.3.0](sdk-codegen-all-v24.2.0...sdk-codegen-all-v24.3.0)
(2024-03-12)


### Features

* error-doc handling in python SDK
([#1440](#1440))
([21daada](21daada))
</details>

<details><summary>looker_sdk: 24.2.1</summary>

##
[24.2.1](looker_sdk-v24.2.0...looker_sdk-v24.2.1)
(2024-03-12)


### Features

* error-doc handling in python SDK
([#1440](#1440))
([21daada](21daada))
</details>

<details><summary>embed-components: 24.2.1</summary>

##
[24.2.1](embed-components-v24.2.0...embed-components-v24.2.1)
(2024-03-12)


### Miscellaneous Chores

* **embed-components:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/embed-services bumped from 24.2.0 to 24.2.1
    * @looker/sdk bumped from 24.2.0 to 24.2.1
  * devDependencies
    * @looker/sdk-node bumped from 24.2.0 to 24.2.1
</details>

<details><summary>embed-services: 24.2.1</summary>

##
[24.2.1](embed-services-v24.2.0...embed-services-v24.2.1)
(2024-03-12)


### Miscellaneous Chores

* **embed-services:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from 24.2.0 to 24.2.1
  * devDependencies
    * @looker/sdk-node bumped from 24.2.0 to 24.2.1
</details>

<details><summary>extension-sdk: 24.2.1</summary>

##
[24.2.1](extension-sdk-v24.2.0...extension-sdk-v24.2.1)
(2024-03-12)


### Miscellaneous Chores

* **extension-sdk:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>extension-sdk-react: 24.2.1</summary>

##
[24.2.1](extension-sdk-react-v24.2.0...extension-sdk-react-v24.2.1)
(2024-03-12)


### Miscellaneous Chores

* **extension-sdk-react:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/extension-sdk bumped from 24.2.0 to 24.2.1
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

<details><summary>sdk: 24.2.1</summary>

##
[24.2.1](sdk-v24.2.0...sdk-v24.2.1)
(2024-03-12)


### Miscellaneous Chores

* **sdk:** Synchronize undefined versions
</details>

<details><summary>sdk-node: 24.2.1</summary>

##
[24.2.1](sdk-node-v24.2.0...sdk-node-v24.2.1)
(2024-03-12)


### Miscellaneous Chores

* **sdk-node:** Synchronize undefined versions


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @looker/sdk bumped from 24.2.0 to 24.2.1
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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