Skip to content

Commit

Permalink
Merge branch 'release_24.0' into release_24.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Jun 5, 2024
2 parents 849d93e + 7228c5a commit 0122cdb
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 122 deletions.
67 changes: 35 additions & 32 deletions lib/galaxy/managers/hdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,19 @@ def serialize_display_apps(self, item, key, trans=None, **context):
"""
hda = item
display_apps: List[Dict[str, Any]] = []
for display_app in hda.get_display_applications(trans).values():
app_links = []
for link_app in display_app.links.values():
app_links.append(
{
"target": link_app.url.get("target_frame", "_blank"),
"href": link_app.get_display_url(hda, trans),
"text": gettext.gettext(link_app.name),
}
)
if app_links:
display_apps.append(dict(label=display_app.name, links=app_links))
if hda.state == model.HistoryDatasetAssociation.states.OK and not hda.deleted:
for display_app in hda.get_display_applications(trans).values():
app_links = []
for link_app in display_app.links.values():
app_links.append(
{
"target": link_app.url.get("target_frame", "_blank"),
"href": link_app.get_display_url(hda, trans),
"text": gettext.gettext(link_app.name),
}
)
if app_links:
display_apps.append(dict(label=display_app.name, links=app_links))

return display_apps

Expand All @@ -646,28 +647,30 @@ def serialize_old_display_applications(self, item, key, trans=None, **context):
"""
hda = item
display_apps: List[Dict[str, Any]] = []
if not self.app.config.enable_old_display_applications:
return display_apps

display_link_fn = hda.datatype.get_display_links
for display_app in hda.datatype.get_display_types():
target_frame, display_links = display_link_fn(
hda,
display_app,
self.app,
trans.request.base,
)
if (
self.app.config.enable_old_display_applications
and hda.state == model.HistoryDatasetAssociation.states.OK
and not hda.deleted
):
display_link_fn = hda.datatype.get_display_links
for display_app in hda.datatype.get_display_types():
target_frame, display_links = display_link_fn(
hda,
display_app,
self.app,
trans.request.base,
)

if len(display_links) > 0:
display_label = hda.datatype.get_display_label(display_app)
if len(display_links) > 0:
display_label = hda.datatype.get_display_label(display_app)

app_links = []
for display_name, display_link in display_links:
app_links.append(
{"target": target_frame, "href": display_link, "text": gettext.gettext(display_name)}
)
if app_links:
display_apps.append(dict(label=display_label, links=app_links))
app_links = []
for display_name, display_link in display_links:
app_links.append(
{"target": target_frame, "href": display_link, "text": gettext.gettext(display_name)}
)
if app_links:
display_apps.append(dict(label=display_label, links=app_links))

return display_apps

Expand Down
67 changes: 33 additions & 34 deletions lib/galaxy/web/framework/middleware/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
When an exception is thrown from the wrapper application, this logs
the exception and displays an error page.
"""
import logging
import sys
import traceback
from io import StringIO
Expand All @@ -25,6 +26,8 @@
reporter,
)

log = logging.getLogger(__name__)

__all__ = ("ErrorMiddleware", "handle_exception")


Expand Down Expand Up @@ -169,10 +172,11 @@ def __call__(self, environ, start_response):
for expect in environ.get("paste.expected_exceptions", []):
if isinstance(exc_info[1], expect):
raise
log.exception("Uncaught Exception")
start_response("500 Internal Server Error", [("content-type", "text/html")], exc_info)
# @@: it would be nice to deal with bad content types here
response = self.exception_handler(exc_info, environ)
return [response]
return [response.encode(errors="ignore")]
finally:
# clean up locals...
exc_info = None
Expand All @@ -183,7 +187,7 @@ def make_catching_iter(self, app_iter, environ, sr_checker):
return app_iter
return CatchingIter(app_iter, environ, sr_checker, self)

def exception_handler(self, exc_info, environ):
def exception_handler(self, exc_info, environ) -> str:
simple_html_error = False
if self.xmlhttp_key:
get_vars = wsgilib.parse_querystring(environ)
Expand All @@ -192,7 +196,6 @@ def exception_handler(self, exc_info, environ):
return handle_exception(
exc_info,
environ["wsgi.errors"],
html=True,
debug_mode=self.debug_mode,
error_email=self.error_email,
error_log=self.error_log,
Expand Down Expand Up @@ -341,7 +344,6 @@ def extraData(self):
def handle_exception(
exc_info,
error_stream,
html=True,
debug_mode=False,
error_email=None,
error_log=None,
Expand All @@ -355,7 +357,7 @@ def handle_exception(
error_message=None,
simple_html_error=False,
environ=None,
):
) -> str:
"""
For exception handling outside of a web context
Expand Down Expand Up @@ -386,54 +388,51 @@ def handle_exception(
smtp_use_tls=smtp_use_tls,
subject_prefix=error_subject_prefix,
)
rep_err = send_report(rep, exc_data, html=html)
rep_err = send_report(rep, exc_data, html=True)
if rep_err:
extra_data += rep_err
else:
reported = True
if error_log:
rep = reporter.LogReporter(filename=error_log)
rep_err = send_report(rep, exc_data, html=html)
rep_err = send_report(rep, exc_data, html=True)
if rep_err:
extra_data += rep_err
else:
reported = True
if show_exceptions_in_wsgi_errors:
rep = reporter.FileReporter(file=error_stream)
rep_err = send_report(rep, exc_data, html=html)
rep_err = send_report(rep, exc_data, html=True)
if rep_err:
extra_data += rep_err
else:
reported = True
else:
error_stream.write(f"Error - {exc_data.exception_type}: {exc_data.exception_value}\n")
if html:
if debug_mode and simple_html_error:
return_error = formatter.format_html(
exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False
)
reported = True
elif debug_mode and not simple_html_error:
error_html = formatter.format_html(exc_data, include_hidden_frames=True, include_reusable=False)
head_html = formatter.error_css + formatter.hide_display_js
return_error = error_template(head_html, error_html, extra_data)
extra_data = ""
reported = True
else:
msg = (
error_message
or """
An error occurred.
"""
)
extra = "<p><b>The error has been logged to our team.</b>"
if "sentry_event_id" in environ:
extra += " If you want to contact us about this error, please reference the following<br><br>"
extra += f"<b><large>GURU MEDITATION: #{environ['sentry_event_id']}</large></b>"
extra += "</p>"
return_error = error_template("", msg, extra)
if debug_mode and simple_html_error:
return_error = formatter.format_html(
exc_data, include_hidden_frames=False, include_reusable=False, show_extra_data=False
)
reported = True
elif debug_mode and not simple_html_error:
error_html = formatter.format_html(exc_data, include_hidden_frames=True, include_reusable=False)
head_html = formatter.error_css + formatter.hide_display_js
return_error = error_template(head_html, error_html, extra_data)
extra_data = ""
reported = True
else:
return_error = None
msg = (
error_message
or """
An error occurred.
"""
)
extra = "<p><b>The error has been logged to our team.</b>"
if "sentry_event_id" in environ:
extra += " If you want to contact us about this error, please reference the following<br><br>"
extra += f"<b><large>GURU MEDITATION: #{environ['sentry_event_id']}</large></b>"
extra += "</p>"
return_error = error_template("", msg, extra)
if not reported and error_stream:
err_report = formatter.format_text(exc_data, show_hidden_frames=True)
err_report += f"\n{'-' * 60}\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/managers/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def create_repository(trans: ProvidesUserContext, request: CreateRepositoryReque
type=request.type_,
description=request.synopsis,
long_description=request.description,
user_id=user.id,
user=user,
category_ids=category_ids,
remote_repository_url=request.remote_repository_url,
homepage_url=request.homepage_url,
Expand Down
3 changes: 1 addition & 2 deletions lib/tool_shed/util/hg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ def get_hgrc_path(repo_path):
return os.path.join(repo_path, ".hg", "hgrc")


def create_hgrc_file(app, repository):
def create_hgrc_file(app, repository, repo_path):
# Since we support both http and https, we set `push_ssl` to False to
# override the default (which is True) in the Mercurial API.
# The hg purge extension purges all files and directories not being tracked
# by Mercurial in the current repository. It will remove unknown files and
# empty directories. This is not currently used because it is not supported
# in the Mercurial API.
repo_path = repository.repo_path(app)
hgrc_path = get_hgrc_path(repo_path)
with open(hgrc_path, "w") as fp:
fp.write("[paths]\n")
Expand Down
11 changes: 5 additions & 6 deletions lib/tool_shed/util/hgweb_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import threading
from datetime import date

from galaxy.util import unicodify

log = logging.getLogger(__name__)

new_hgweb_config_template = """
Expand All @@ -20,6 +18,7 @@ def __init__(self):
self.hgweb_config_dir = None
self.in_memory_config = None
self.lock = threading.Lock()
self.hgweb_repo_prefix = None

def add_entry(self, lhs, rhs):
"""Add an entry in the hgweb.config file for a new repository."""
Expand All @@ -35,8 +34,8 @@ def add_entry(self, lhs, rhs):
self.in_memory_config.set("paths", lhs, rhs)
# Persist our in-memory configuration.
self.write_config()
except Exception as e:
log.debug("Exception in HgWebConfigManager.add_entry(): %s", unicodify(e))
except Exception:
log.exception("Exception in HgWebConfigManager.add_entry()")
finally:
self.lock.release()

Expand All @@ -51,8 +50,8 @@ def change_entry(self, old_lhs, new_lhs, new_rhs):
self.in_memory_config.set("paths", new_lhs, new_rhs)
# Persist our in-memory configuration.
self.write_config()
except Exception as e:
log.debug("Exception in HgWebConfigManager.change_entry(): %s", unicodify(e))
except Exception:
log.exception("Exception in HgWebConfigManager.change_entry()")
finally:
self.lock.release()

Expand Down
Loading

0 comments on commit 0122cdb

Please sign in to comment.