-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Handle Errors and Tables in Query #20658
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
Changes from all commits
6233a7b
2abb91e
c823dfc
f87d701
06f5dde
e9f16cf
56ecff3
4639159
92631d4
49d6684
4c95151
0fabfd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from azure.core.exceptions import HttpResponseError | ||
|
|
||
| class LogsQueryError(object): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it an AzureError?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this need not be an azure error. |
||
| """The code and message for an error. | ||
|
|
||
| All required parameters must be populated in order to send to Azure. | ||
|
|
||
| :ivar code: A machine readable error code. | ||
| :vartype code: str | ||
| :ivar message: A human readable error message. | ||
| :vartype message: str | ||
| :ivar details: error details. | ||
| :vartype details: list[~monitor_query_client.models.ErrorDetail] | ||
| :ivar innererror: Inner error details if they exist. | ||
| :vartype innererror: ~azure.monitor.query.LogsQueryError | ||
| :ivar additional_properties: Additional properties that can be provided on the error info | ||
| object. | ||
| :vartype additional_properties: object | ||
| :ivar bool is_error: Boolean check for error item when iterating over list of | ||
| results. Always True for an instance of a LogsQueryError. | ||
| """ | ||
| def __init__( | ||
| self, | ||
| **kwargs | ||
| ): | ||
| self.code = kwargs.get('code', None) | ||
| self.message = kwargs.get('message', None) | ||
| self.details = kwargs.get('details', None) | ||
| self.innererror = kwargs.get('innererror', None) | ||
| self.additional_properties = kwargs.get('additional_properties', None) | ||
| self.is_error = True | ||
|
|
||
| @classmethod | ||
| def _from_generated(cls, generated): | ||
| if not generated: | ||
| return None | ||
| details = None | ||
| if generated.details is not None: | ||
| details = [d.serialize() for d in generated.details] | ||
| return cls( | ||
| code=generated.code, | ||
| message=generated.message, | ||
| innererror=cls._from_generated(generated.innererror) if generated.innererror else None, | ||
| additional_properties=generated.additional_properties, | ||
| details=details, | ||
| ) | ||
|
|
||
| class QueryPartialErrorException(HttpResponseError): | ||
xiangyan99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """There is a partial failure in query operation. This is thrown for a single query operation | ||
| when allow_partial_errors is set to False. | ||
|
|
||
| :ivar code: A machine readable error code. | ||
| :vartype code: str | ||
| :ivar message: A human readable error message. | ||
| :vartype message: str | ||
| :ivar details: error details. | ||
| :vartype details: list[~monitor_query_client.models.ErrorDetail] | ||
| :ivar innererror: Inner error details if they exist. | ||
| :vartype innererror: ~azure.monitor.query.LogsQueryError | ||
| :ivar additional_properties: Additional properties that can be provided on the error info | ||
| object. | ||
| :vartype additional_properties: object | ||
| """ | ||
|
|
||
| def __init__(self, **kwargs): | ||
| error = kwargs.pop('error', None) | ||
| if error: | ||
| self.code = error.code | ||
| self.message = error.message | ||
| self.details = [d.serialize() for d in error.details] if error.details else None | ||
| self.innererror = LogsQueryError._from_generated(error.innererror) if error.innererror else None | ||
| self.additional_properties = error.additional_properties | ||
| super(QueryPartialErrorException, self).__init__(message=self.message) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,13 +41,21 @@ def get_metrics_authentication_policy( | |
|
|
||
| raise TypeError("Unsupported credential") | ||
|
|
||
| def process_error(exception): | ||
| raise_error = HttpResponseError | ||
| raise raise_error(message=exception.message, response=exception.response) | ||
|
|
||
| def order_results(request_order, mapping, obj): | ||
| def order_results(request_order, mapping, obj, err, allow_partial_errors=False): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to put allow_partial_errors into kwargs?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. normally i would say yes - but here, i don't see the kwargs expanding anytime soon - plus this is an internal method, so we can change it if we think it's necessary |
||
| ordered = [mapping[id] for id in request_order] | ||
| return [obj._from_generated(rsp) for rsp in ordered] # pylint: disable=protected-access | ||
| results = [] | ||
| for item in ordered: | ||
| if not item.body.error: | ||
| results.append(obj._from_generated(item.body)) # pylint: disable=protected-access | ||
| else: | ||
| error = item.body.error | ||
| if allow_partial_errors and error.code == 'PartialError': | ||
| res = obj._from_generated(item.body) # pylint: disable=protected-access | ||
| res.partial_error = err._from_generated(error) # pylint: disable=protected-access | ||
| results.append(res) | ||
| else: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we raise if allow_partial_errors = False and there is error?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no - in case of batch, we return the error object instead of the result object of course, we raise when something fatal happens (like auth error for instance) |
||
| results.append(err._from_generated(error)) # pylint: disable=protected-access | ||
| return results | ||
|
|
||
| def construct_iso8601(timespan=None): | ||
| if not timespan: | ||
|
|
@@ -90,3 +98,23 @@ def native_col_type(col_type, value): | |
|
|
||
| def process_row(col_types, row): | ||
| return [native_col_type(col_types[ind], val) for ind, val in enumerate(row)] | ||
|
|
||
| def process_error(error, model): | ||
| try: | ||
| model = model._from_generated(error.model.error) # pylint: disable=protected-access | ||
| except AttributeError: # model can be none | ||
| pass | ||
| raise HttpResponseError( | ||
| message=error.message, | ||
| response=error.response, | ||
| model=model) | ||
|
|
||
| def process_prefer(server_timeout, include_statistics, include_visualization): | ||
| prefer = "" | ||
| if server_timeout: | ||
| prefer += "wait=" + str(server_timeout) + "," | ||
| if include_statistics: | ||
| prefer += "include-statistics=true," | ||
| if include_visualization: | ||
| prefer += "include-render=true" | ||
| return prefer.rstrip(",") | ||
Uh oh!
There was an error while loading. Please reload this page.