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

Format backend error msg #626

Merged
merged 18 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cdci_data_analysis/analysis/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ def run_query(self, product_type,
except InternalError as e:
if hasattr(e, 'message') and e.message is not None:
message = e.message
tail_message = ('The support team has been notified, '
'and we are investigating to resolve the issue as soon as possible\n\n'
'If you are willing to help us, please use the "Write a feedback" button below. '
'We will make sure to respond to any feedback provided')
else:
message = ('Your request produced an unusual result. It might not be what you expected. '
'It is possible that this particular parameter selection should indeed lead to this outcome '
Expand All @@ -468,15 +472,22 @@ def run_query(self, product_type,
'but for now, we unfortunately can not be certain all cases like this are detected. '
'We try to discover on our own and directly address any temporary issue. '
'But some issues might slip past us. If you are willing to help us, '
'please use "provide feedback" button below. We would greatly appreciate it!\n\n'
'please use "Write a feedback" button below. We would greatly appreciate it!\n\n'
'This additional information might help:\n\n'
)
e_message = f'Instrument: {self.name}, product: {product_type} failed!\n'
tail_message = ''
e_message = f'Instrument: {self.name}, product: {product_type}\n\n{tail_message}'

debug_message = ''
if e.payload is not None and e.payload.get('exception', None) is not None:
debug_message = repr(e.payload['exception'])

query_out.set_failed(product_type,
message=message,
e_message=e_message,
logger=logger,
sentry_dsn=sentry_dsn,
debug_message=debug_message,
excep=e)

except Exception as e: # we shall not do that
Expand Down
19 changes: 10 additions & 9 deletions cdci_data_analysis/analysis/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ def set_query_exception(self,
except Exception as e:
logger.error('unable to represent %s due to %s, setting blank', excep, e)
e_message = ''

sentry.capture_message(e_message)


logger.error('set_query_exception with %s (%s) during %s', e_message, debug_message, failed_operation)

if message is None:
message = '%s' % message_prepend_str
message += ' failed: %s' % (failed_operation)
Expand All @@ -206,16 +205,18 @@ def set_query_exception(self,
else:
pass

msg_str = '%s' % logger_prepend_str
msg_str += 'failed: %s' % failed_operation
msg_str += ' error: %s' % e_message
msg_str += ' debug : %s' % debug_message
logger_msg_str = '%s' % logger_prepend_str
logger_msg_str += 'failed: %s' % failed_operation
logger_msg_str += ' error: %s' % e_message
logger_msg_str += ' debug : %s' % debug_message
if extra_message is not None:
msg_str += ' message: %s' % (extra_message)
logger_msg_str += ' message: %s' % (extra_message)

if logger is not None:
logger.info(msg_str)
logger.info(logger_msg_str)

sentry_msg_str = f'failed: {failed_operation} error: {e_message} debug: {debug_message}'
sentry.capture_message(sentry_msg_str)
self.set_status(status, message=message, error_message=e_message, debug_message=str(debug_message))

def __repr__(self):
Expand Down
45 changes: 10 additions & 35 deletions cdci_data_analysis/analysis/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@


import logging
import os
import time as _time
import json
from collections import OrderedDict

import sentry_sdk
import decorator
import decorator
import traceback
import numpy as np


from .parameters import (Parameter,
ParameterGroup,
ParameterRange,
from .parameters import (Parameter,
ParameterGroup,
ParameterRange,
ParameterTuple,
Name,
Angle,
Expand All @@ -40,15 +39,14 @@
DetectionThreshold,
Float,
TimeDelta,

# these are not used here but wildcard-imported from this module by integral plugin
SpectralBoundary,
Integer
)
from .products import SpectralFitProduct, QueryOutput, QueryProductList, ImageProduct
from .io_helper import FilePath
from .exceptions import RequestNotUnderstood, UnfortunateRequestResults, BadRequest, InternalError
import traceback
from .exceptions import RequestNotUnderstood, InternalError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -455,7 +453,6 @@ def test_communication(self, instrument, job=None, query_type='Real', logger=Non
debug_message=debug_message)

except Exception as e:
sentry_sdk.capture_exception(e)
raise InternalError(f"unexpected error while testing communication with {instrument}, {e!r}")

status = query_out.get_status()
Expand Down Expand Up @@ -604,8 +601,6 @@ def get_query_products(self,
api=api)
job.set_done()

#self.query_prod_list = QueryProductList(prod_list=prod_list)

#DONE
query_out.set_done(message=messages['message'], debug_message=str(messages['debug_message']),job_status=job.status,status=status,comment=messages['comment'],warning=messages['warning'])
#print('-->', query_out.status_dictionary)
Expand All @@ -614,30 +609,10 @@ def get_query_products(self,
raise

except Exception as e:
# TODO: could we avoid these? they make error tracking hard
# TODO we could use the very same approach used when test_communication fails

#status=1
logger.exception("failed to get query products")
internal_error_message = "Error when getting query products"
job.set_failed()
if os.environ.get('DISPATCHER_DEBUG', 'yes') == 'yes':
raise
exception_message = getattr(e, 'message', '')
if return_progress:
logger.exception("failed to get progress run")
e_message = f'Failed when getting the progress run for job {job.job_id}:\n{exception_message}'
else:
logger.exception("failed to get query products")
e_message = f'Failed when getting query products for job {job.job_id}:\n{exception_message}'
messages['debug_message'] = repr(e) + ' : ' + getattr(e, 'debug_message', '')

query_out.set_failed('get_query_products found job failed',
logger=logger,
sentry_dsn=sentry_dsn,
excep=e,
e_message=e_message,
debug_message=messages['debug_message'])
# TODO to use this approach when we will refactor the handling of exceptions
# raise InternalError(e_message)
raise InternalError(internal_error_message, payload={'exception': e})

logger.info('--> data_server_query_status %d' % query_out.get_status())
logger.info('--> end product query ')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,8 @@ def test_status_details_email_done(gunicorn_dispatcher_live_fixture, dispatcher_
# check the additional status details within the email
assert 'email_status_details' in jdata
assert jdata['email_status_details'] == {
'exception_message': 'failing query\nInstrument: empty, product: failing failed!\n',
'exception_message': 'Error when getting query products\nInstrument: empty, product: failing\n\n'
'The support team has been notified, and we are investigating to resolve the issue as soon as possible',
'status': 'empty_product'
}

Expand Down
Loading