Skip to content

Commit

Permalink
Improve error logging
Browse files Browse the repository at this point in the history
Plus tidy + type annotations
  • Loading branch information
MetRonnie committed Sep 1, 2022
1 parent 9533656 commit 70d4e0e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
5 changes: 2 additions & 3 deletions cylc/flow/network/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ async def send_multi(self, topic, data, serializer=None):
"""
if self.socket:
# don't attempt to send anything if we are in the process of
# shutting down
self.topics.add(topic)
self.socket.send_multipart(
[topic, serialize_data(data, serializer)]
)
# else we are in the process of shutting down - don't send anything

async def publish(self, items):
"""Publish topics.
Expand All @@ -98,4 +97,4 @@ async def publish(self, items):
try:
await gather_coros(self.send_multi, items)
except Exception as exc:
LOG.error('publish: %s', exc)
LOG.exception(f"publish: {exc}")
1 change: 0 additions & 1 deletion cylc/flow/network/replier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Server for workflow runtime API."""

import getpass # noqa: F401
from queue import Queue

import zmq
Expand Down
17 changes: 12 additions & 5 deletions cylc/flow/network/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def start(self, barrier):

self.operate()

async def stop(self, reason: Union[Exception, str]) -> None:
async def stop(self, reason: Union[BaseException, str]) -> None:
"""Stop the TCP servers, and clean up authentication.
This method must be called/awaited from a different thread to the
Expand Down Expand Up @@ -385,12 +385,19 @@ def graphql(
if executed.errors:
errors: List[Any] = []
for error in executed.errors:
LOG.error(error)
if hasattr(error, '__traceback__'):
import traceback
errors.append({'error': {
'message': str(error),
'traceback': traceback.format_exception(
error.__class__, error, error.__traceback__)}})
formatted_tb = traceback.format_exception(
type(error), error, error.__traceback__
)
LOG.error("".join(formatted_tb))
errors.append({
'error': {
'message': str(error),
'traceback': formatted_tb
}
})
continue
errors.append(getattr(error, 'message', None))
return errors
Expand Down
6 changes: 3 additions & 3 deletions cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def check_workflow_stalled(self):
self.timers[self.EVENT_STALL_TIMEOUT].reset()
return self.is_stalled

async def shutdown(self, reason: Exception) -> None:
async def shutdown(self, reason: BaseException) -> None:
"""Gracefully shut down the scheduler."""
# At the moment this method must be called from the main_loop.
# In the future it should shutdown the main_loop itself but
Expand All @@ -1719,7 +1719,7 @@ async def shutdown(self, reason: Exception) -> None:
# Re-raise exception to be caught higher up (sets the exit code)
raise exc from None

async def _shutdown(self, reason: Exception) -> None:
async def _shutdown(self, reason: BaseException) -> None:
"""Shutdown the workflow."""
shutdown_msg = "Workflow shutting down"
if isinstance(reason, SchedulerStop):
Expand Down Expand Up @@ -1977,7 +1977,7 @@ def _check_startup_opts(self) -> None:
f"option --{opt}=reload is only valid for restart"
)

async def handle_exception(self, exc: Exception) -> NoReturn:
async def handle_exception(self, exc: BaseException) -> NoReturn:
"""Gracefully shut down the scheduler given a caught exception.
Re-raises the exception to be caught higher up (sets the exit code).
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/test_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from time import sleep

import pytest
import zmq

Expand Down
4 changes: 1 addition & 3 deletions tests/unit/network/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from time import sleep

from cylc.flow.network.publisher import WorkflowPublisher, serialize_data
from cylc.flow.network.publisher import serialize_data


def test_serialize_data():
Expand Down

0 comments on commit 70d4e0e

Please sign in to comment.