Skip to main content

flowrlib/
debugger_handler.rs

1use serde_json::Value;
2
3use flowcore::errors::Result;
4use flowcore::model::input::Input;
5use flowcore::model::output_connection::OutputConnection;
6use flowcore::model::runtime_function::RuntimeFunction;
7
8use crate::block::Block;
9use crate::debug_command::DebugCommand;
10use crate::job::Job;
11use crate::run_state::RunState;
12use crate::run_state::State;
13
14/// `[DebugHandler]` trait that must be implemented by clients wishing to interface with the debugger
15///
16/// Programs that wish to offer a debugger user interface (such as a CLI or UI) should implement
17/// this trait. The [Coordinator][crate::coordinator::Coordinator] uses it to interact with the
18/// client for debugging.
19pub trait DebuggerHandler {
20    /// Start the debugger - which swallows the first message to initialize the connection
21    fn start(&mut self);
22    /// a breakpoint has been hit on a Job being created
23    fn job_breakpoint(&mut self, job: &Job, function: &RuntimeFunction, states: Vec<State>);
24    /// A breakpoint set on creation of a `Block` matching `block` has been hit
25    fn block_breakpoint(&mut self, block: &Block);
26    /// A breakpoint set on the unblocking of a flow has been hit
27    fn flow_unblock_breakpoint(&mut self, flow_id: usize);
28    /// A breakpoint on sending a value from a specific function or to a specific function was hit
29    #[allow(clippy::too_many_arguments)]
30    fn send_breakpoint(
31        &mut self,
32        source_function_name: &str,
33        source_function_id: usize,
34        output_route: &str,
35        value: &Value,
36        destination_id: usize,
37        destination_name: &str,
38        io_name: &str,
39        input_number: usize,
40    );
41    /// A job error occurred during execution of the flow
42    fn job_error(&mut self, job: &Job);
43    /// A specific job completed
44    fn job_completed(&mut self, job: &Job);
45    /// returns a set of blocks
46    fn blocks(&mut self, blocks: Vec<Block>);
47    /// returns an output's connections
48    fn outputs(&mut self, output: Vec<OutputConnection>);
49    /// returns an inputs state
50    fn input(&mut self, input: Input);
51    /// lists all functions
52    fn function_list(&mut self, functions: &[RuntimeFunction]);
53    /// returns the state of a function
54    fn function_states(&mut self, function: RuntimeFunction, function_states: Vec<State>);
55    /// returns the global run state
56    fn run_state(&mut self, run_state: &RunState);
57    /// a string message from the Debugger
58    fn message(&mut self, message: String);
59    /// a panic occurred during execution
60    fn panic(&mut self, state: &RunState, error_message: String);
61    /// the debugger is exiting
62    fn debugger_exiting(&mut self);
63    /// The debugger is resetting the runtime state
64    fn debugger_resetting(&mut self);
65    /// An error occurred in the debugger
66    fn debugger_error(&mut self, error: String);
67    /// execution of the flow is starting
68    fn execution_starting(&mut self);
69    /// Execution of the flow fn `execution_ended`
70    fn execution_ended(&mut self);
71    /// Get a command for the debugger to perform
72    ///
73    /// # Errors
74    ///
75    /// Returns an error if the next command cannot be fetched, usually related to networking
76    fn get_command(&mut self, state: &RunState) -> Result<DebugCommand>;
77}