@@ -14,6 +14,9 @@ use crate::{
1414
1515#[ derive( Debug ) ]
1616pub enum CompileError {
17+ NodeIdMissing {
18+ node_index : usize ,
19+ } ,
1720 DuplicateNodeId {
1821 node_id : i64 ,
1922 } ,
@@ -37,6 +40,11 @@ pub enum CompileError {
3740impl CompileError {
3841 pub fn as_runtime_error ( & self ) -> RuntimeError {
3942 match self {
43+ CompileError :: NodeIdMissing { node_index } => RuntimeError :: new (
44+ "T-CORE-000100" ,
45+ "FlowCompileError" ,
46+ format ! ( "Node at index {} is missing database id" , node_index) ,
47+ ) ,
4048 CompileError :: DuplicateNodeId { node_id } => RuntimeError :: new (
4149 "T-CORE-000101" ,
4250 "FlowCompileError" ,
@@ -90,10 +98,12 @@ pub fn compile_flow(
9098) -> Result < CompiledFlow , CompileError > {
9199 let mut node_idx_by_id = HashMap :: with_capacity ( nodes. len ( ) ) ;
92100 for ( idx, node) in nodes. iter ( ) . enumerate ( ) {
93- if node_idx_by_id. insert ( node. database_id , idx) . is_some ( ) {
94- return Err ( CompileError :: DuplicateNodeId {
95- node_id : node. database_id ,
96- } ) ;
101+ let Some ( node_id) = node. database_id else {
102+ return Err ( CompileError :: NodeIdMissing { node_index : idx } ) ;
103+ } ;
104+
105+ if node_idx_by_id. insert ( node_id, idx) . is_some ( ) {
106+ return Err ( CompileError :: DuplicateNodeId { node_id } ) ;
97107 }
98108 }
99109
@@ -108,12 +118,15 @@ pub fn compile_flow(
108118
109119 let mut compiled_nodes = Vec :: with_capacity ( nodes. len ( ) ) ;
110120 for node in nodes {
121+ let node_id = node
122+ . database_id
123+ . expect ( "compiler validates node database ids before compilation" ) ;
111124 let next_idx = match node. next_node_id {
112125 Some ( next_id) => match node_idx_by_id. get ( & next_id) . copied ( ) {
113126 Some ( idx) => Some ( idx) ,
114127 None => {
115128 return Err ( CompileError :: NextNodeMissing {
116- node_id : node . database_id ,
129+ node_id,
117130 next_node_id : next_id,
118131 } ) ;
119132 }
@@ -127,13 +140,13 @@ pub fn compile_flow(
127140 for ( parameter_index, parameter) in node. parameters . iter ( ) . enumerate ( ) {
128141 let Some ( node_value) = parameter. value . as_ref ( ) else {
129142 return Err ( CompileError :: ParameterValueMissing {
130- node_id : node . database_id ,
143+ node_id,
131144 parameter_index,
132145 } ) ;
133146 } ;
134147 let Some ( value) = node_value. value . as_ref ( ) else {
135148 return Err ( CompileError :: ParameterValueMissing {
136- node_id : node . database_id ,
149+ node_id,
137150 parameter_index,
138151 } ) ;
139152 } ;
@@ -155,7 +168,7 @@ pub fn compile_flow(
155168 }
156169 None => {
157170 return Err ( CompileError :: SubFlowExecutionReferenceMissing {
158- node_id : node . database_id ,
171+ node_id,
159172 parameter_index,
160173 } ) ;
161174 }
@@ -170,7 +183,7 @@ pub fn compile_flow(
170183 }
171184
172185 compiled_nodes. push ( CompiledNode {
173- id : node . database_id ,
186+ id : node_id ,
174187 handler_id : node. runtime_function_id ,
175188 execution_target,
176189 next_idx,
@@ -186,14 +199,11 @@ pub fn compile_flow(
186199}
187200
188201fn execution_target_for ( node : & NodeFunction ) -> NodeExecutionTarget {
189- if node. definition_source . is_empty ( )
190- || node. definition_source == "taurus"
191- || node. definition_source . starts_with ( "draco" )
192- {
193- NodeExecutionTarget :: Local
194- } else {
195- NodeExecutionTarget :: Remote {
196- service : node. definition_source . clone ( ) ,
197- }
202+ match node. definition_source . as_deref ( ) {
203+ None | Some ( "" ) | Some ( "taurus" ) => NodeExecutionTarget :: Local ,
204+ Some ( source) if source. starts_with ( "draco" ) => NodeExecutionTarget :: Local ,
205+ Some ( service) => NodeExecutionTarget :: Remote {
206+ service : service. to_string ( ) ,
207+ } ,
198208 }
199209}
0 commit comments