I don't think this exception is useful, versus just raising a
RuntimeError.
The current code catches exceptions at the top-level, logs it (using
logging.error) and prints it to stderr. I don't think it's useful to
log using logging.error, since it also goes to stderr. And I don't
think it's useful to manually print the exception. Instead, let them
escape and let Python print them using its regular uncaught exception
mechanism, which ends up printing them on stderr too.
Change-Id: Ice797d4b672dc5eba7312c4cabb2740806c37a2a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10894
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
import socket
import struct
import logging
import socket
import struct
import logging
-class UnexpectedInput(RuntimeError):
- pass
-
-
# An entry within the index of an LTTng data stream.
class _LttngDataStreamIndexEntry:
def __init__(
# An entry within the index of an LTTng data stream.
class _LttngDataStreamIndexEntry:
def __init__(
version, tracing_session_id
)
else:
version, tracing_session_id
)
else:
- raise UnexpectedInput("Unknown command type {}".format(cmd_type))
+ raise RuntimeError("Unknown command type {}".format(cmd_type))
def _pack(self, fmt: str, *args: Any):
# Force network byte order
def _pack(self, fmt: str, *args: Any):
# Force network byte order
def _get_tracing_session_state(self, tracing_session_id: int):
if tracing_session_id not in self._ts_states:
def _get_tracing_session_state(self, tracing_session_id: int):
if tracing_session_id not in self._ts_states:
"Unknown tracing session ID {}".format(tracing_session_id)
)
"Unknown tracing session ID {}".format(tracing_session_id)
)
cmd_type = type(cmd)
if cmd_type not in self._command_handlers:
cmd_type = type(cmd)
if cmd_type not in self._command_handlers:
"Unexpected command: cmd-cls-name={}".format(cmd.__class__.__name__)
)
"Unexpected command: cmd-cls-name={}".format(cmd.__class__.__name__)
)
info = ts_state.tracing_session_descriptor.info
if ts_state.is_attached:
info = ts_state.tracing_session_descriptor.info
if ts_state.is_attached:
"Cannot attach to tracing session `{}`: viewer is already attached".format(
info.name
)
"Cannot attach to tracing session `{}`: viewer is already attached".format(
info.name
)
info = ts_state.tracing_session_descriptor.info
if not ts_state.is_attached:
info = ts_state.tracing_session_descriptor.info
if not ts_state.is_attached:
"Cannot detach to tracing session `{}`: viewer is not attached".format(
info.name
)
"Cannot detach to tracing session `{}`: viewer is not attached".format(
info.name
)
logging.info("Client closed connection.")
if data:
logging.info("Client closed connection.")
if data:
"Client closed connection after having sent {} command bytes.".format(
len(data)
)
"Client closed connection after having sent {} command bytes.".format(
len(data)
)
try:
cmd = self._codec.decode(data)
except struct.error as exc:
try:
cmd = self._codec.decode(data)
except struct.error as exc:
- raise UnexpectedInput("Malformed command: {}".format(exc)) from exc
+ raise RuntimeError("Malformed command: {}".format(exc)) from exc
if cmd is not None:
logging.info(
if cmd is not None:
logging.info(
cmd = self._recv_command()
if type(cmd) is not _LttngLiveViewerConnectCommand:
cmd = self._recv_command()
if type(cmd) is not _LttngLiveViewerConnectCommand:
'First command is not "connect": cmd-cls-name={}'.format(
cmd.__class__.__name__
)
'First command is not "connect": cmd-cls-name={}'.format(
cmd.__class__.__name__
)
)
args = parser.parse_args(args=remaining_args)
)
args = parser.parse_args(args=remaining_args)
- try:
- sessions_filename = args.sessions_filename # type: str
- trace_path_prefix = args.trace_path_prefix # type: str | None
- sessions = _session_descriptors_from_path(
- sessions_filename,
- trace_path_prefix,
- )
+ sessions_filename = args.sessions_filename # type: str
+ trace_path_prefix = args.trace_path_prefix # type: str | None
+ sessions = _session_descriptors_from_path(
+ sessions_filename,
+ trace_path_prefix,
+ )
- port = args.port # type: int | None
- port_filename = args.port_filename # type: str
- max_query_data_response_size = (
- args.max_query_data_response_size
- ) # type: int | None
- LttngLiveServer(port, port_filename, sessions, max_query_data_response_size)
- except UnexpectedInput as exc:
- logging.error(str(exc))
- print(exc, file=sys.stderr)
- sys.exit(1)
+ port = args.port # type: int | None
+ port_filename = args.port_filename # type: str
+ max_query_data_response_size = args.max_query_data_response_size # type: int | None
+ LttngLiveServer(port, port_filename, sessions, max_query_data_response_size)