1use core::fmt::{Debug, Display};
6use std::string::ToString;
7use std::sync::Arc;
8
9use melodium_common::{
10 descriptor::{DataTrait, DescribedType, Flow, Identifier, IdentifierRequirement, Status},
11 executive::TrackId,
12};
13
14use crate::{building::CheckStep, design::Value, designer::Reference};
15
16#[derive(Debug, Clone)]
18pub enum LogicErrorKind {
19 CollectionUndefined,
21 UncommitedDescriptor { identifier: Identifier },
23 NoDesigner { identifier: Identifier },
25 ErroneousDesign { identifier: Identifier },
27 ErroneousChecks,
29 UnavailableDesign { identifier: Identifier },
31 LaunchExpectTreatment {
33 wrong_identifier: Option<Identifier>,
34 },
35 LaunchWrongParameter { parameter: String },
37 UnresolvableSecret { parameter: String, error: String },
39 DuplicateSecretSource { scheme: String },
41 UnknownSecretScheme { secret: String, scheme: String },
43 LaunchTreatmentExpectModel { wrong_identifier: Identifier },
45 NoDirectTrack { id: TrackId },
47 UnexistingVariable {
49 identifier: Identifier,
50 parameter: String,
51 variable: String,
52 },
53 UnexistingContextVariable {
55 identifier: Identifier,
56 parameter: String,
57 context: Identifier,
58 variable: String,
59 },
60 UnexistingParameter {
62 scope: Identifier,
63 called: Identifier,
64 parameter: String,
65 },
66 UnmatchingDataType {
68 scope: Identifier,
69 called: Identifier,
70 parameter: String,
71 value: Value,
72 expected: DescribedType,
73 given: DescribedType,
74 },
75 UnsetParameter {
77 scope: Identifier,
78 called: Identifier,
79 parameter: String,
80 },
81 MultipleParameterAssignation {
83 scope: Identifier,
84 called: Identifier,
85 parameter: String,
86 },
87 NoValue {
89 scope: Identifier,
90 called: Identifier,
91 parameter: String,
92 },
93 NoContext {
95 scope: Identifier,
96 model: Identifier,
97 name: String,
98 parameter: String,
99 },
100 UnavailableContext {
102 scope: Identifier,
103 context: Identifier,
104 },
105 ConnectionInputNotFound {
107 scope: Identifier,
108 to: Identifier,
109 input: String,
110 },
111 ConnectionSelfInputNotFound { scope: Identifier, input: String },
113 ConnectionOutputNotFound {
115 scope: Identifier,
116 from: Identifier,
117 output: String,
118 },
119 ConnectionSelfOutputNotFound { scope: Identifier, output: String },
121 UnexistingTreatment {
123 scope: Identifier,
124 claimed: IdentifierRequirement,
125 },
126 UnexistingModel {
128 scope: Identifier,
129 claimed: IdentifierRequirement,
130 },
131 UnexistingContext {
133 scope: Identifier,
134 claimed: IdentifierRequirement,
135 },
136 UnexistingFunction {
138 scope: Identifier,
139 claimed: IdentifierRequirement,
140 },
141 UnexistingData {
143 scope: Identifier,
144 claimed: IdentifierRequirement,
145 },
146 UndeclaredModel { scope: Identifier, model: String },
148 AlreadyDeclaredModel { scope: Identifier, model: String },
150 UndeclaredTreatment {
152 scope: Identifier,
153 treatment: String,
154 },
155 AlreadyDeclaredTreatment {
157 scope: Identifier,
158 treatment: String,
159 },
160 UnexistingConnectionType {
162 scope: Identifier,
163 from: String,
164 output: String,
165 to: String,
166 input: String,
167 output_flow: Flow,
168 output_type: DescribedType,
169 input_flow: Flow,
170 input_type: DescribedType,
171 },
172 UnsatisfiedOutput { scope: Identifier, output: String },
174 OverloadedOutput { scope: Identifier, output: String },
176 UnmatchingModelType {
178 scope: Identifier,
179 called: Identifier,
180 name: String,
181 expected: Identifier,
182 given_name: String,
183 given: Identifier,
184 },
185 UnexistingParametricModel {
187 scope: Identifier,
188 called: Identifier,
189 parametric_model: String,
190 },
191 UnsetModel {
193 scope: Identifier,
194 called: Identifier,
195 parametric_model: String,
196 },
197 AlreadyIncludedBuildStep {
199 treatment: Identifier,
200 cause_step: CheckStep,
201 check_steps: Vec<CheckStep>,
202 },
203 UnsatisfiedInput {
205 scope: Option<Identifier>,
206 treatment: String,
207 input: String,
208 },
209 OverloadedInput {
211 scope: Identifier,
212 treatment: String,
213 input: String,
214 },
215 ConstRequiredVarProvided {
217 scope: Identifier,
218 called: Identifier,
219 parameter: String,
220 variable: String,
221 },
222 ConstRequiredContextProvided {
224 scope: Identifier,
225 called: Identifier,
226 parameter: String,
227 context: Identifier,
228 entry: String,
229 },
230 ModelInstanciationConstOnly {
232 scope: Identifier,
233 called: Identifier,
234 name: String,
235 parameter: String,
236 },
237 ConstRequiredFunctionReturnsVar {
239 scope: Identifier,
240 called: Identifier,
241 parameter: String,
242 function: Identifier,
243 },
244 UnmatchingNumberOfParameters {
246 scope: Identifier,
247 function: Identifier,
248 },
249 UnexistingGeneric {
251 scope: Identifier,
252 element: Identifier,
253 name: String,
254 described_type: DescribedType,
255 },
256 UndefinedGeneric {
258 scope: Identifier,
259 element: Identifier,
260 described_type: DescribedType,
261 },
262 UnsatisfiedTraits {
264 scope: Identifier,
265 element: Identifier,
266 described_type: DescribedType,
267 unsatisfied_traits: Vec<DataTrait>,
268 },
269}
270
271impl LogicErrorKind {
272 fn described_type_details(described_type: &DescribedType) -> String {
273 match described_type.final_type() {
274 DescribedType::Data(data) => format!("data type {}", data.identifier()),
275 DescribedType::Generic(generic) => format!("generic {}", generic),
276 dt => dt.to_string(),
277 }
278 }
279}
280
281impl Display for LogicErrorKind {
282 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
283 match self {
284 LogicErrorKind::CollectionUndefined => write!(f, "No collection defined"),
285 LogicErrorKind::UncommitedDescriptor { identifier } => write!(f, "Uncommited descriptor, no designer available for '{identifier}'"),
286 LogicErrorKind::NoDesigner {identifier } => write!(f, "Nothing to commit, as no designer available for '{identifier}'"),
287 LogicErrorKind::ErroneousDesign {identifier} => write!(f, "Design for '{identifier}' contains errors and cannot be commited"),
288 LogicErrorKind::ErroneousChecks => write!(f, "Building coherency checks found errors, build cannot be made"),
289 LogicErrorKind::UnavailableDesign { identifier } => write!(f, "Unavailable design for '{identifier}'"),
290 LogicErrorKind::LaunchExpectTreatment { wrong_identifier } => if let Some(id) = wrong_identifier {
291 write!(f, "Launch must be done using a treatment, '{id}' is not one") } else {
292 write!(f, "Launch must be done using a treatment, but no valid identifier is provided")
293 },
294 LogicErrorKind::LaunchWrongParameter { parameter } => write!(f, "Parameter '{parameter}' has no valid value for launch"),
295 LogicErrorKind::UnresolvableSecret { parameter, error } => write!(f, "Secret of parameter '{parameter}' cannot be resolved: {error}"),
296 LogicErrorKind::DuplicateSecretSource { scheme } => write!(f, "A secret source is already registered for '{scheme}:'"),
297 LogicErrorKind::UnknownSecretScheme { secret, scheme } => write!(f, "Secret '{secret}' is located in '{scheme}:', for which no source is registered on this engine"),
298 LogicErrorKind::LaunchTreatmentExpectModel {wrong_identifier} => write!(f, "Launch must be done with a treatment that does not require model, but '{wrong_identifier}' expect some model"),
299 LogicErrorKind::NoDirectTrack { id } => write!(f, "No directly instancied track exist for id {id}"),
300 LogicErrorKind::UnexistingVariable {identifier,
301 parameter,
302 variable,} => write!(f, "Referenced '{variable}' variable for '{parameter}' parameter doesn't exist in '{identifier}'"),
303 LogicErrorKind::UnexistingContextVariable{identifier,
304 parameter,
305 context,
306 variable,} => write!(f, "Referenced '{variable}' context value for '{parameter}' does not exist within '{context}' context in '{identifier}'"),
307 LogicErrorKind::UnexistingParameter {
308 scope,
309 called,
310 parameter,
311 } => write!(f, "Parameter '{parameter}' does not exist for '{called}' in '{scope}'"),
312 LogicErrorKind::UnmatchingDataType {
313 scope, called, parameter, value, expected, given
314 } => write!(f, "Datatype does not match for '{parameter}' of '{called}' in '{scope}', {expected} ({}) expected but '{value}' is {given} ({})", Self::described_type_details(expected), Self::described_type_details(given)),
315 LogicErrorKind::UnsetParameter { scope, called, parameter } => write!(f, "Parameter '{parameter}' of '{called}' is not set in '{scope}'"),
316 LogicErrorKind::MultipleParameterAssignation { scope, called, parameter } => write!(f, "Parameter '{parameter}' of '{called}' assigned multiple times in '{scope}'"),
317 LogicErrorKind::NoValue {scope, called, parameter} => write!(f, "No value assigned to '{parameter}' of '{called}' in '{scope}'"),
318 LogicErrorKind::NoContext{scope, model, name, parameter } => write!(f, "Context used for parameter '{parameter}' of model '{name}' type '{model}' in '{scope}', but context values cannot be used for models"),
319 LogicErrorKind::UnavailableContext{scope, context} => write!(f, "Context '{context}' not available in '{scope}'"),
320 LogicErrorKind::ConnectionInputNotFound{scope: _, to, input} => write!(f, "Input '{input}' is not provided by '{to}'"),
321 LogicErrorKind::ConnectionSelfInputNotFound { scope, input } => write!(f, "Input '{input}' does not exist for '{scope}'"),
322 LogicErrorKind::ConnectionOutputNotFound { scope: _, from, output } => write!(f, "Output '{output}' is not provided by '{from}'"),
323 LogicErrorKind::ConnectionSelfOutputNotFound{scope, output} => write!(f, "Output '{output}' does not exist for '{scope}'"),
324 LogicErrorKind::UnexistingTreatment{scope: _, claimed} => write!(f, "Treatment '{claimed}' does not exist"),
325 LogicErrorKind::UnexistingModel { scope: _, claimed } => write!(f, "Model '{claimed}' does not exist"),
326 LogicErrorKind::UnexistingContext { scope: _, claimed } => write!(f, "Context '{claimed}' does not exist"),
327 LogicErrorKind::UnexistingFunction{ scope: _, claimed } => write!(f, "Function '{claimed}' does not exist"),
328 LogicErrorKind::UnexistingData{ scope: _, claimed } => write!(f, "Data type '{claimed}' does not exist"),
329 LogicErrorKind::UndeclaredModel { scope, model } => write!(f, "Model '{model}' is not declared in '{scope}'"),
330 LogicErrorKind::AlreadyDeclaredModel { scope, model } => write!(f, "Model '{model}' is already declared in '{scope}'"),
331 LogicErrorKind::UndeclaredTreatment { scope, treatment } => write!(f, "Treatment '{treatment}' is not declared in '{scope}'"),
332 LogicErrorKind::AlreadyDeclaredTreatment { scope, treatment } => write!(f, "Treatment '{treatment}' is already declared in '{scope}'"),
333 LogicErrorKind::UnexistingConnectionType { scope, from, output, to, input, output_type, input_type, output_flow, input_flow } => write!(f, "Connection from '{from}' to '{to}' in '{scope}' is not possible, '{output}' is {output_flow}<{output_type}> ({}) but '{input}' is {input_flow}<{input_type}> ({})", Self::described_type_details(output_type), Self::described_type_details(input_type)),
334 LogicErrorKind::UnsatisfiedOutput { scope, output } => write!(f, "Output '{output}' is not satisfied in '{scope}'"),
335 LogicErrorKind::OverloadedOutput { scope, output } => write!(f, "Output '{output}' is overloaded in '{scope}', only one connection is possible to 'Self' outputs"),
336 LogicErrorKind::UnmatchingModelType { scope: _, called, name, expected, given_name, given } => write!(f, "Model '{name}' for '{called}' is expected to be '{expected}', but given '{given_name}' is '{given}' and not based on it"),
337 LogicErrorKind::UnexistingParametricModel { scope, called, parametric_model } => write!(f, "Parametric model '{parametric_model}' does not exist for '{called}' in '{scope}'"),
338 LogicErrorKind::UnsetModel { scope, called, parametric_model } => write!(f, "No model assigned to '{parametric_model}' of '{called}' in '{scope}'"),
339 LogicErrorKind::AlreadyIncludedBuildStep { treatment , cause_step,check_steps} => write!(f, "Treatment '{treatment}' is referring to same instanciation of itself, causing infinite connection loop ({cause_step} already present in {})", check_steps.iter().map(|cs| cs.to_string()).collect::<Vec<_>>().join(", ")),
340 LogicErrorKind::UnsatisfiedInput { scope, treatment, input } => if let Some(id) = scope {write!(f, "Input '{input}' of '{treatment}' is not satisfied in '{id}'")} else {write!(f, "Entrypoint have input '{input}' that must be satisfied")},
341 LogicErrorKind::OverloadedInput { scope, treatment, input } => write!(f, "Input '{input}' of '{treatment}' is overloaded in '{scope}'"),
342 LogicErrorKind::ConstRequiredVarProvided { scope, called, parameter, variable } => write!(f, "Parameter '{parameter}' of '{called}' is constant but provided '{variable}' is variable in '{scope}'"),
343 LogicErrorKind::ConstRequiredContextProvided { scope, called, parameter, context, entry: _ } => write!(f, "Parameter '{parameter}' of '{called}' is constant but context '{context}' is provided in '{scope}', contexts are implicitly variable"),
344 LogicErrorKind::ModelInstanciationConstOnly { scope, called, name, parameter } => write!(f, "Variable provided for parameter '{parameter}' of model '{name}' from type '{called}' in '{scope}', model instanciations can only get constants"),
345 LogicErrorKind::ConstRequiredFunctionReturnsVar { scope, called, parameter, function } => write!(f, "Parameter '{parameter}' of '{called}' is constant but provided '{function}' have variable return value in '{scope}'"),
346 LogicErrorKind::UnmatchingNumberOfParameters { scope, function } => write!(f, "Number of parameters given do not match for function '{function}' in '{scope}'"),
347 LogicErrorKind::UnexistingGeneric { scope, element, name, described_type } => write!(f, "The generic type '{name}' ({}) doesn't exist for '{element}' in '{scope}'", Self::described_type_details(described_type)),
348 LogicErrorKind::UndefinedGeneric { scope, element, described_type } => write!(f, "Generic '{described_type}' ({}) is not defined for '{element}' in '{scope}'", Self::described_type_details(described_type)),
349 LogicErrorKind::UnsatisfiedTraits { scope, element, described_type, unsatisfied_traits } => write!(f, "Type '{described_type}' ({}) does not satisfy trait {} for '{element}' in '{scope}'", Self::described_type_details(described_type), unsatisfied_traits.iter().map(|tr| tr.to_string()).collect::<Vec<_>>().join(" + ")),
350 }
351 }
352}
353
354#[derive(Debug, Clone)]
356pub struct LogicError {
357 pub id: u32,
359 pub kind: LogicErrorKind,
361 pub design_reference: Option<Arc<dyn Reference>>,
363}
364
365impl LogicError {
366 pub fn collection_undefined(id: u32, design_reference: Option<Arc<dyn Reference>>) -> Self {
368 Self {
369 id,
370 design_reference,
371 kind: LogicErrorKind::CollectionUndefined,
372 }
373 }
374
375 pub fn uncommited_descriptor(
377 id: u32,
378 identifier: Identifier,
379 design_reference: Option<Arc<dyn Reference>>,
380 ) -> Self {
381 Self {
382 id,
383 design_reference,
384 kind: LogicErrorKind::UncommitedDescriptor { identifier },
385 }
386 }
387
388 pub fn no_designer(
390 id: u32,
391 identifier: Identifier,
392 design_reference: Option<Arc<dyn Reference>>,
393 ) -> Self {
394 Self {
395 id,
396 design_reference,
397 kind: LogicErrorKind::NoDesigner { identifier },
398 }
399 }
400
401 pub fn erroneous_design(
403 id: u32,
404 identifier: Identifier,
405 design_reference: Option<Arc<dyn Reference>>,
406 ) -> Self {
407 Self {
408 id,
409 design_reference,
410 kind: LogicErrorKind::ErroneousDesign { identifier },
411 }
412 }
413
414 pub fn erroneous_checks(id: u32, design_reference: Option<Arc<dyn Reference>>) -> Self {
416 Self {
417 id,
418 design_reference,
419 kind: LogicErrorKind::ErroneousChecks,
420 }
421 }
422
423 pub fn unavailable_design(
425 id: u32,
426 identifier: Identifier,
427 design_reference: Option<Arc<dyn Reference>>,
428 ) -> Self {
429 Self {
430 id,
431 design_reference,
432 kind: LogicErrorKind::UnavailableDesign { identifier },
433 }
434 }
435
436 pub fn launch_expect_treatment(id: u32, wrong_identifier: Option<Identifier>) -> Self {
438 Self {
439 id,
440 design_reference: None,
441 kind: LogicErrorKind::LaunchExpectTreatment { wrong_identifier },
442 }
443 }
444
445 pub fn launch_wrong_parameter(id: u32, parameter: String) -> Self {
446 Self {
447 id,
448 design_reference: None,
449 kind: LogicErrorKind::LaunchWrongParameter { parameter },
450 }
451 }
452
453 pub fn unresolvable_secret(id: u32, parameter: String, error: String) -> Self {
455 Self {
456 id,
457 design_reference: None,
458 kind: LogicErrorKind::UnresolvableSecret { parameter, error },
459 }
460 }
461
462 pub fn duplicate_secret_source(id: u32, scheme: String) -> Self {
464 Self {
465 id,
466 design_reference: None,
467 kind: LogicErrorKind::DuplicateSecretSource { scheme },
468 }
469 }
470
471 pub fn unknown_secret_scheme(id: u32, secret: String, scheme: String) -> Self {
473 Self {
474 id,
475 design_reference: None,
476 kind: LogicErrorKind::UnknownSecretScheme { secret, scheme },
477 }
478 }
479
480 pub fn launch_treatment_expect_model(id: u32, wrong_identifier: Identifier) -> Self {
482 Self {
483 id,
484 design_reference: None,
485 kind: LogicErrorKind::LaunchTreatmentExpectModel { wrong_identifier },
486 }
487 }
488
489 pub fn no_direct_track(id: u32, track_id: TrackId) -> Self {
490 Self {
491 id,
492 design_reference: None,
493 kind: LogicErrorKind::NoDirectTrack { id: track_id },
494 }
495 }
496
497 pub fn unexisting_variable(
499 id: u32,
500 identifier: Identifier,
501 parameter: String,
502 variable: String,
503 design_reference: Option<Arc<dyn Reference>>,
504 ) -> Self {
505 Self {
506 id,
507 design_reference,
508 kind: LogicErrorKind::UnexistingVariable {
509 identifier,
510 parameter,
511 variable,
512 },
513 }
514 }
515
516 pub fn unexisting_context_variable(
518 id: u32,
519 identifier: Identifier,
520 parameter: String,
521 context: Identifier,
522 variable: String,
523 design_reference: Option<Arc<dyn Reference>>,
524 ) -> Self {
525 Self {
526 id,
527 design_reference,
528 kind: LogicErrorKind::UnexistingContextVariable {
529 identifier,
530 parameter,
531 context,
532 variable,
533 },
534 }
535 }
536
537 pub fn unexisting_parameter(
539 id: u32,
540 scope: Identifier,
541 called: Identifier,
542 parameter: String,
543 design_reference: Option<Arc<dyn Reference>>,
544 ) -> Self {
545 Self {
546 id,
547 design_reference,
548 kind: LogicErrorKind::UnexistingParameter {
549 scope,
550 called,
551 parameter,
552 },
553 }
554 }
555
556 pub fn unmatching_datatype(
558 id: u32,
559 scope: Identifier,
560 called: Identifier,
561 parameter: String,
562 value: Value,
563 expected: DescribedType,
564 given: DescribedType,
565 design_reference: Option<Arc<dyn Reference>>,
566 ) -> Self {
567 Self {
568 id,
569 design_reference,
570 kind: LogicErrorKind::UnmatchingDataType {
571 scope,
572 called,
573 parameter,
574 value,
575 expected,
576 given,
577 },
578 }
579 }
580
581 pub fn unset_parameter(
583 id: u32,
584 scope: Identifier,
585 called: Identifier,
586 parameter: String,
587 design_reference: Option<Arc<dyn Reference>>,
588 ) -> Self {
589 Self {
590 id,
591 design_reference,
592 kind: LogicErrorKind::UnsetParameter {
593 scope,
594 called,
595 parameter,
596 },
597 }
598 }
599
600 pub fn multiple_parameter_assignation(
602 id: u32,
603 scope: Identifier,
604 called: Identifier,
605 parameter: String,
606 design_reference: Option<Arc<dyn Reference>>,
607 ) -> Self {
608 Self {
609 id,
610 design_reference,
611 kind: LogicErrorKind::MultipleParameterAssignation {
612 scope,
613 called,
614 parameter,
615 },
616 }
617 }
618
619 pub fn no_value(
621 id: u32,
622 scope: Identifier,
623 called: Identifier,
624 parameter: String,
625 design_reference: Option<Arc<dyn Reference>>,
626 ) -> Self {
627 Self {
628 id,
629 design_reference,
630 kind: LogicErrorKind::NoValue {
631 scope,
632 called,
633 parameter,
634 },
635 }
636 }
637
638 pub fn no_context(
640 id: u32,
641 scope: Identifier,
642 model: Identifier,
643 name: String,
644 parameter: String,
645 design_reference: Option<Arc<dyn Reference>>,
646 ) -> Self {
647 Self {
648 id,
649 design_reference,
650 kind: LogicErrorKind::NoContext {
651 scope,
652 model,
653 name,
654 parameter,
655 },
656 }
657 }
658
659 pub fn unavailable_context(
661 id: u32,
662 scope: Identifier,
663 context: Identifier,
664 design_reference: Option<Arc<dyn Reference>>,
665 ) -> Self {
666 Self {
667 id,
668 design_reference,
669 kind: LogicErrorKind::UnavailableContext { scope, context },
670 }
671 }
672
673 pub fn connection_input_not_found(
675 id: u32,
676 scope: Identifier,
677 to: Identifier,
678 input: String,
679 design_reference: Option<Arc<dyn Reference>>,
680 ) -> Self {
681 Self {
682 id,
683 design_reference,
684 kind: LogicErrorKind::ConnectionInputNotFound { scope, to, input },
685 }
686 }
687
688 pub fn connection_self_input_not_found(
690 id: u32,
691 scope: Identifier,
692 input: String,
693 design_reference: Option<Arc<dyn Reference>>,
694 ) -> Self {
695 Self {
696 id,
697 design_reference,
698 kind: LogicErrorKind::ConnectionSelfInputNotFound { scope, input },
699 }
700 }
701
702 pub fn connection_output_not_found(
704 id: u32,
705 scope: Identifier,
706 from: Identifier,
707 output: String,
708 design_reference: Option<Arc<dyn Reference>>,
709 ) -> Self {
710 Self {
711 id,
712 design_reference,
713 kind: LogicErrorKind::ConnectionOutputNotFound {
714 scope,
715 from,
716 output,
717 },
718 }
719 }
720
721 pub fn connection_self_output_not_found(
723 id: u32,
724 scope: Identifier,
725 output: String,
726 design_reference: Option<Arc<dyn Reference>>,
727 ) -> Self {
728 Self {
729 id,
730 design_reference,
731 kind: LogicErrorKind::ConnectionSelfOutputNotFound { scope, output },
732 }
733 }
734
735 pub fn unexisting_treatment(
737 id: u32,
738 scope: Identifier,
739 claimed: IdentifierRequirement,
740 design_reference: Option<Arc<dyn Reference>>,
741 ) -> Self {
742 Self {
743 id,
744 design_reference,
745 kind: LogicErrorKind::UnexistingTreatment { scope, claimed },
746 }
747 }
748
749 pub fn unexisting_model(
751 id: u32,
752 scope: Identifier,
753 claimed: IdentifierRequirement,
754 design_reference: Option<Arc<dyn Reference>>,
755 ) -> Self {
756 Self {
757 id,
758 design_reference,
759 kind: LogicErrorKind::UnexistingModel { scope, claimed },
760 }
761 }
762
763 pub fn unexisting_context(
765 id: u32,
766 scope: Identifier,
767 claimed: IdentifierRequirement,
768 design_reference: Option<Arc<dyn Reference>>,
769 ) -> Self {
770 Self {
771 id,
772 design_reference,
773 kind: LogicErrorKind::UnexistingContext { scope, claimed },
774 }
775 }
776
777 pub fn unexisting_function(
779 id: u32,
780 scope: Identifier,
781 claimed: IdentifierRequirement,
782 design_reference: Option<Arc<dyn Reference>>,
783 ) -> Self {
784 Self {
785 id,
786 design_reference,
787 kind: LogicErrorKind::UnexistingFunction { scope, claimed },
788 }
789 }
790
791 pub fn unexisting_data(
793 id: u32,
794 scope: Identifier,
795 claimed: IdentifierRequirement,
796 design_reference: Option<Arc<dyn Reference>>,
797 ) -> Self {
798 Self {
799 id,
800 design_reference,
801 kind: LogicErrorKind::UnexistingData { scope, claimed },
802 }
803 }
804
805 pub fn undeclared_model(
807 id: u32,
808 scope: Identifier,
809 model: String,
810 design_reference: Option<Arc<dyn Reference>>,
811 ) -> Self {
812 Self {
813 id,
814 design_reference,
815 kind: LogicErrorKind::UndeclaredModel { scope, model },
816 }
817 }
818
819 pub fn already_declared_model(
821 id: u32,
822 scope: Identifier,
823 model: String,
824 design_reference: Option<Arc<dyn Reference>>,
825 ) -> Self {
826 Self {
827 id,
828 design_reference,
829 kind: LogicErrorKind::AlreadyDeclaredModel { scope, model },
830 }
831 }
832
833 pub fn undeclared_treatment(
835 id: u32,
836 scope: Identifier,
837 treatment: String,
838 design_reference: Option<Arc<dyn Reference>>,
839 ) -> Self {
840 Self {
841 id,
842 design_reference,
843 kind: LogicErrorKind::UndeclaredTreatment { scope, treatment },
844 }
845 }
846
847 pub fn already_declared_treatment(
849 id: u32,
850 scope: Identifier,
851 treatment: String,
852 design_reference: Option<Arc<dyn Reference>>,
853 ) -> Self {
854 Self {
855 id,
856 design_reference,
857 kind: LogicErrorKind::AlreadyDeclaredTreatment { scope, treatment },
858 }
859 }
860
861 pub fn unexisting_connexion_type(
863 id: u32,
864 scope: Identifier,
865 from: String,
866 output: String,
867 to: String,
868 input: String,
869 output_flow: Flow,
870 output_type: DescribedType,
871 input_flow: Flow,
872 input_type: DescribedType,
873 design_reference: Option<Arc<dyn Reference>>,
874 ) -> Self {
875 Self {
876 id,
877 design_reference,
878 kind: LogicErrorKind::UnexistingConnectionType {
879 scope,
880 from,
881 output,
882 to,
883 input,
884 output_flow,
885 output_type,
886 input_flow,
887 input_type,
888 },
889 }
890 }
891
892 pub fn unsatisfied_output(
894 id: u32,
895 scope: Identifier,
896 output: String,
897 design_reference: Option<Arc<dyn Reference>>,
898 ) -> Self {
899 Self {
900 id,
901 design_reference,
902 kind: LogicErrorKind::UnsatisfiedOutput { scope, output },
903 }
904 }
905
906 pub fn overloaded_output(
908 id: u32,
909 scope: Identifier,
910 output: String,
911 design_reference: Option<Arc<dyn Reference>>,
912 ) -> Self {
913 Self {
914 id,
915 design_reference,
916 kind: LogicErrorKind::OverloadedOutput { scope, output },
917 }
918 }
919
920 pub fn unmatching_model_type(
922 id: u32,
923 scope: Identifier,
924 called: Identifier,
925 name: String,
926 expected: Identifier,
927 given_name: String,
928 given: Identifier,
929 design_reference: Option<Arc<dyn Reference>>,
930 ) -> Self {
931 Self {
932 id,
933 design_reference,
934 kind: LogicErrorKind::UnmatchingModelType {
935 scope,
936 called,
937 name,
938 expected,
939 given_name,
940 given,
941 },
942 }
943 }
944
945 pub fn unexisting_parametric_model(
947 id: u32,
948 scope: Identifier,
949 called: Identifier,
950 parametric_model: String,
951 design_reference: Option<Arc<dyn Reference>>,
952 ) -> Self {
953 Self {
954 id,
955 design_reference,
956 kind: LogicErrorKind::UnexistingParametricModel {
957 scope,
958 called,
959 parametric_model,
960 },
961 }
962 }
963
964 pub fn unset_model(
966 id: u32,
967 scope: Identifier,
968 called: Identifier,
969 parametric_model: String,
970 design_reference: Option<Arc<dyn Reference>>,
971 ) -> Self {
972 Self {
973 id,
974 design_reference,
975 kind: LogicErrorKind::UnsetModel {
976 scope,
977 called,
978 parametric_model,
979 },
980 }
981 }
982
983 pub fn already_included_build_step(
985 id: u32,
986 treatment: Identifier,
987 cause_step: CheckStep,
988 check_steps: Vec<CheckStep>,
989 design_reference: Option<Arc<dyn Reference>>,
990 ) -> Self {
991 Self {
992 id,
993 design_reference,
994 kind: LogicErrorKind::AlreadyIncludedBuildStep {
995 treatment,
996 cause_step,
997 check_steps,
998 },
999 }
1000 }
1001
1002 pub fn unsatisfied_input(
1004 id: u32,
1005 scope: Option<Identifier>,
1006 treatment: String,
1007 input: String,
1008 design_reference: Option<Arc<dyn Reference>>,
1009 ) -> Self {
1010 Self {
1011 id,
1012 design_reference,
1013 kind: LogicErrorKind::UnsatisfiedInput {
1014 scope,
1015 treatment,
1016 input,
1017 },
1018 }
1019 }
1020
1021 pub fn overloaded_input(
1023 id: u32,
1024 scope: Identifier,
1025 treatment: String,
1026 input: String,
1027 design_reference: Option<Arc<dyn Reference>>,
1028 ) -> Self {
1029 Self {
1030 id,
1031 design_reference,
1032 kind: LogicErrorKind::OverloadedInput {
1033 scope,
1034 treatment,
1035 input,
1036 },
1037 }
1038 }
1039
1040 pub fn const_required_var_provided(
1042 id: u32,
1043 scope: Identifier,
1044 called: Identifier,
1045 parameter: String,
1046 variable: String,
1047 design_reference: Option<Arc<dyn Reference>>,
1048 ) -> Self {
1049 Self {
1050 id,
1051 design_reference,
1052 kind: LogicErrorKind::ConstRequiredVarProvided {
1053 scope,
1054 called,
1055 parameter,
1056 variable,
1057 },
1058 }
1059 }
1060
1061 pub fn const_required_context_provided(
1063 id: u32,
1064 scope: Identifier,
1065 called: Identifier,
1066 parameter: String,
1067 context: Identifier,
1068 entry: String,
1069 design_reference: Option<Arc<dyn Reference>>,
1070 ) -> Self {
1071 Self {
1072 id,
1073 design_reference,
1074 kind: LogicErrorKind::ConstRequiredContextProvided {
1075 scope,
1076 called,
1077 parameter,
1078 context,
1079 entry,
1080 },
1081 }
1082 }
1083
1084 pub fn model_instanciation_const_only(
1086 id: u32,
1087 scope: Identifier,
1088 called: Identifier,
1089 name: String,
1090 parameter: String,
1091 design_reference: Option<Arc<dyn Reference>>,
1092 ) -> Self {
1093 Self {
1094 id,
1095 design_reference,
1096 kind: LogicErrorKind::ModelInstanciationConstOnly {
1097 scope,
1098 called,
1099 name,
1100 parameter,
1101 },
1102 }
1103 }
1104
1105 pub fn const_required_function_returns_var(
1107 id: u32,
1108 scope: Identifier,
1109 called: Identifier,
1110 parameter: String,
1111 function: Identifier,
1112 design_reference: Option<Arc<dyn Reference>>,
1113 ) -> Self {
1114 Self {
1115 id,
1116 design_reference,
1117 kind: LogicErrorKind::ConstRequiredFunctionReturnsVar {
1118 scope,
1119 called,
1120 parameter,
1121 function,
1122 },
1123 }
1124 }
1125
1126 pub fn unmatching_number_of_parameters(
1128 id: u32,
1129 scope: Identifier,
1130 function: Identifier,
1131 design_reference: Option<Arc<dyn Reference>>,
1132 ) -> Self {
1133 Self {
1134 id,
1135 design_reference,
1136 kind: LogicErrorKind::UnmatchingNumberOfParameters { scope, function },
1137 }
1138 }
1139
1140 pub fn unexisting_generic(
1142 id: u32,
1143 scope: Identifier,
1144 element: Identifier,
1145 name: String,
1146 described_type: DescribedType,
1147 design_reference: Option<Arc<dyn Reference>>,
1148 ) -> Self {
1149 Self {
1150 id,
1151 design_reference,
1152 kind: LogicErrorKind::UnexistingGeneric {
1153 scope,
1154 element,
1155 name,
1156 described_type,
1157 },
1158 }
1159 }
1160
1161 pub fn undefined_generic(
1163 id: u32,
1164 scope: Identifier,
1165 element: Identifier,
1166 described_type: DescribedType,
1167 design_reference: Option<Arc<dyn Reference>>,
1168 ) -> Self {
1169 Self {
1170 id,
1171 design_reference,
1172 kind: LogicErrorKind::UndefinedGeneric {
1173 scope,
1174 element,
1175 described_type,
1176 },
1177 }
1178 }
1179
1180 pub fn unsatisfied_traits(
1182 id: u32,
1183 scope: Identifier,
1184 element: Identifier,
1185 described_type: DescribedType,
1186 unsatisfied_traits: Vec<DataTrait>,
1187 design_reference: Option<Arc<dyn Reference>>,
1188 ) -> Self {
1189 Self {
1190 id,
1191 design_reference,
1192 kind: LogicErrorKind::UnsatisfiedTraits {
1193 scope,
1194 element,
1195 described_type,
1196 unsatisfied_traits,
1197 },
1198 }
1199 }
1200}
1201
1202impl Display for LogicError {
1203 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1204 write!(f, "D{:04}: {}", self.id, self.kind)
1205 }
1206}
1207
1208pub type LogicErrors = Vec<LogicError>;
1209pub type LogicResult<T> = Status<T, LogicError, LogicError>;
1210
1211impl From<LogicError> for LogicErrors {
1212 fn from(value: LogicError) -> Self {
1213 vec![value]
1214 }
1215}