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

chore: use exc_info to pass errors to log warnings #20252

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ def get_all_table_names_in_schema( # pylint: disable=unused-argument
database=self, inspector=self.inspector, schema=schema
)
return [(table, schema) for table in tables]
except Exception as ex: # pylint: disable=broad-except
logger.warning(ex)
except Exception: # pylint: disable=broad-except
logger.warning("Get all table names in schema failed", exc_info=True)
return []

@cache_util.memoized_func(
Expand Down Expand Up @@ -607,8 +607,8 @@ def get_all_view_names_in_schema( # pylint: disable=unused-argument
database=self, inspector=self.inspector, schema=schema
)
return [(view, schema) for view in views]
except Exception as ex: # pylint: disable=broad-except
logger.warning(ex)
except Exception: # pylint: disable=broad-except
logger.warning("Get all view names failed", exc_info=True)
return []

@cache_util.memoized_func(
Expand Down Expand Up @@ -777,8 +777,8 @@ def _has_view(
view_names: List[str] = []
try:
view_names = dialect.get_view_names(connection=conn, schema=schema)
except Exception as ex: # pylint: disable=broad-except
logger.warning(ex)
except Exception: # pylint: disable=broad-except
logger.warning("Has view failed", exc_info=True)
return view_name in view_names

def has_view(self, view_name: str, schema: Optional[str] = None) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion superset/utils/async_query_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def parse_jwt_from_request(self, req: Request) -> Dict[str, Any]:
try:
return jwt.decode(token, self._jwt_secret, algorithms=["HS256"])
except Exception as ex:
logger.warning(ex)
logger.warning("Parse jwt failed", exc_info=True)
raise AsyncQueryTokenException("Failed to parse token") from ex

def init_job(self, channel_id: str, user_id: Optional[str]) -> Dict[str, Any]:
Expand Down
18 changes: 9 additions & 9 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def api(f: Callable[..., FlaskResponse]) -> Callable[..., FlaskResponse]:
def wraps(self: "BaseSupersetView", *args: Any, **kwargs: Any) -> FlaskResponse:
try:
return f(self, *args, **kwargs)
except NoAuthorizationError as ex:
logger.warning(ex)
except NoAuthorizationError:
logger.warning("Api failed- no authorization", exc_info=True)
return json_error_response(get_error_msg(), status=401)
except Exception as ex: # pylint: disable=broad-except
logger.exception(ex)
Expand All @@ -206,15 +206,15 @@ def wraps(self: "BaseSupersetView", *args: Any, **kwargs: Any) -> FlaskResponse:
try:
return f(self, *args, **kwargs)
except SupersetSecurityException as ex:
logger.warning(ex)
logger.warning("SupersetSecurityException", exc_info=True)
return json_errors_response(
errors=[ex.error], status=ex.status, payload=ex.payload
)
except SupersetErrorsException as ex:
logger.warning(ex, exc_info=True)
return json_errors_response(errors=ex.errors, status=ex.status)
except SupersetErrorException as ex:
logger.warning(ex)
logger.warning("SupersetErrorException", exc_info=True)
return json_errors_response(errors=[ex.error], status=ex.status)
except SupersetException as ex:
if ex.status >= 500:
Expand Down Expand Up @@ -397,20 +397,20 @@ def get_error_level_from_status_code( # pylint: disable=invalid-name
# SupersetErrorException or SupersetErrorsException
@superset_app.errorhandler(SupersetErrorException)
def show_superset_error(ex: SupersetErrorException) -> FlaskResponse:
logger.warning(ex)
logger.warning("SupersetErrorException", exc_info=True)
return json_errors_response(errors=[ex.error], status=ex.status)


@superset_app.errorhandler(SupersetErrorsException)
def show_superset_errors(ex: SupersetErrorsException) -> FlaskResponse:
logger.warning(ex)
logger.warning("SupersetErrorsException", exc_info=True)
return json_errors_response(errors=ex.errors, status=ex.status)


# Redirect to login if the CSRF token is expired
@superset_app.errorhandler(CSRFError)
def refresh_csrf_token(ex: CSRFError) -> FlaskResponse:
logger.warning(ex)
logger.warning("Refresh CSRF token error", exc_info=True)

if request.is_json:
return show_http_exception(ex)
Expand All @@ -420,7 +420,7 @@ def refresh_csrf_token(ex: CSRFError) -> FlaskResponse:

@superset_app.errorhandler(HTTPException)
def show_http_exception(ex: HTTPException) -> FlaskResponse:
logger.warning(ex)
logger.warning("HTTPException", exc_info=True)
if (
"text/html" in request.accept_mimetypes
and not config["DEBUG"]
Expand All @@ -446,7 +446,7 @@ def show_http_exception(ex: HTTPException) -> FlaskResponse:
# or SupersetErrorsException, with a specific status code and error type
@superset_app.errorhandler(CommandException)
def show_command_errors(ex: CommandException) -> FlaskResponse:
logger.warning(ex)
logger.warning("CommandException", exc_info=True)
if "text/html" in request.accept_mimetypes and not config["DEBUG"]:
path = resource_filename("superset", "static/assets/500.html")
return send_file(path, cache_timeout=0), 500
Expand Down