1use crate::{
2 AudioNodeRef, BusId, ClipId, CompositionId, DataSetId, EffectProblem, EffectResourceId, NodeId,
3 TrackId,
4};
5use alpha2_media::SourceId;
6use std::fmt;
7
8#[derive(Clone, Debug, Eq, PartialEq)]
11pub enum ShapeOwner {
12 Source(SourceId),
14 Clip(ClipId),
16 Node {
18 composition: CompositionId,
20 node: NodeId,
22 },
23}
24
25impl fmt::Display for ShapeOwner {
26 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Self::Source(source) => write!(formatter, "source {source}"),
29 Self::Clip(clip) => write!(formatter, "clip {clip}"),
30 Self::Node { composition, node } => {
31 write!(formatter, "composition {composition} node {node}")
32 }
33 }
34 }
35}
36
37#[derive(Clone, Debug, Eq, PartialEq)]
39pub enum DataOwner {
40 Clip(ClipId),
42 Track(TrackId),
44 Master,
46 Bus(BusId),
48 Transition {
50 track: TrackId,
52 from: ClipId,
54 to: ClipId,
56 },
57 Node {
59 composition: CompositionId,
61 node: NodeId,
63 },
64 Source(SourceId),
66}
67
68impl fmt::Display for DataOwner {
69 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
70 match self {
71 Self::Clip(clip) => write!(formatter, "clip {clip}"),
72 Self::Track(track) => write!(formatter, "track {track}"),
73 Self::Master => formatter.write_str("the master bus"),
74 Self::Bus(bus) => write!(formatter, "bus {bus}"),
75 Self::Transition { track, from, to } => {
76 write!(formatter, "track {track} transition {from} to {to}")
77 }
78 Self::Node { composition, node } => {
79 write!(formatter, "composition {composition} node {node}")
80 }
81 Self::Source(source) => write!(formatter, "source {source}"),
82 }
83 }
84}
85
86#[derive(Clone, Debug, Eq, PartialEq)]
88pub enum EffectOwner {
89 Node {
91 composition: CompositionId,
93 node: NodeId,
95 },
96 Transition {
98 track: TrackId,
100 from: ClipId,
102 to: ClipId,
104 },
105 Source(SourceId),
107}
108
109impl fmt::Display for EffectOwner {
110 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
111 match self {
112 Self::Node { composition, node } => {
113 write!(formatter, "composition {composition} node {node}")
114 }
115 Self::Transition { track, from, to } => {
116 write!(
117 formatter,
118 "the transition from {from} to {to} on track {track}"
119 )
120 }
121 Self::Source(source) => write!(formatter, "source {source}"),
122 }
123 }
124}
125
126impl fmt::Display for EffectProblem {
127 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
128 match self {
129 Self::UnknownBuiltin => formatter.write_str("is not a built-in"),
130 Self::Version { expected } => write!(formatter, "needs version {expected}"),
131 Self::Kind => formatter.write_str("is used as the wrong kind"),
132 Self::UnknownParam(name) => write!(formatter, "has no parameter {name}"),
133 Self::InvalidParam(name) => {
134 write!(
135 formatter,
136 "has a parameter {name} of the wrong type or out of range"
137 )
138 }
139 Self::Inputs => formatter.write_str("does not get exactly its declared inputs"),
140 Self::Resources => formatter.write_str("does not get exactly its declared resources"),
141 }
142 }
143}
144
145#[derive(Clone, Debug, Eq, PartialEq)]
147#[non_exhaustive]
148pub enum ModelError {
149 UnsupportedSchemaVersion {
151 found: u32,
153 },
154 TooManyDataSets {
156 found: usize,
158 maximum: usize,
160 },
161 DuplicateDataSetId(DataSetId),
163 InvalidDataSet {
165 data: DataSetId,
167 problem: crate::DataProblem,
169 },
170 InvalidDataBinding {
172 owner: DataOwner,
174 at: String,
177 problem: crate::BindingProblem,
179 },
180 EmptyIdentifier,
182 DuplicateSourceId(SourceId),
184 DuplicateEffectResourceId(EffectResourceId),
186 DuplicateTrackId(TrackId),
188 DuplicateClipId(ClipId),
190 EmptyLocator {
192 source: SourceId,
194 },
195 AudioOnImage {
197 source: SourceId,
199 },
200 InvalidProvider {
203 source: SourceId,
205 },
206 InvalidFingerprint {
208 source: SourceId,
210 },
211 ContradictoryColor {
214 source: SourceId,
216 },
217 InvalidGenerator {
220 source: SourceId,
222 },
223 InvalidShape {
226 owner: ShapeOwner,
228 at: String,
230 problem: crate::ShapeProblem,
232 },
233 InvalidLayout {
236 owner: ShapeOwner,
238 at: String,
240 problem: crate::LayoutProblem,
242 },
243 InvalidTextRunStyle {
246 owner: ShapeOwner,
248 run: usize,
250 },
251 EmptyEffectResourceLocator {
253 resource: EffectResourceId,
255 },
256 UnknownEffectResource {
258 clip: ClipId,
260 resource: EffectResourceId,
262 },
263 EmptyClipRange {
265 clip: ClipId,
267 },
268 NegativeClipRange {
270 clip: ClipId,
272 },
273 OverlappingClips {
275 track: TrackId,
277 first: ClipId,
279 second: ClipId,
281 },
282 UnknownClipSource {
284 clip: ClipId,
286 source: SourceId,
288 },
289 IncompatibleClipSource {
291 clip: ClipId,
293 track: TrackId,
295 source: SourceId,
297 },
298 InvalidVisualProperties {
300 clip: ClipId,
302 },
303 InvalidAudioProperties {
305 clip: ClipId,
307 },
308 InvalidTrackAudio {
310 track: TrackId,
312 },
313 InvalidMasterAudio,
315 InvalidAudioBus {
317 bus: BusId,
319 },
320 InvalidAudioSend {
322 from: AudioNodeRef,
324 to: BusId,
326 },
327 UnknownAudioBus {
329 from: AudioNodeRef,
331 bus: BusId,
333 },
334 DuplicateAudioBus {
336 bus: BusId,
338 },
339 AudioRoutingCycle {
341 node: AudioNodeRef,
343 },
344 TooManyAudioBuses {
346 found: usize,
348 maximum: usize,
350 },
351 UnknownAudioSidechain {
353 owner: Option<AudioNodeRef>,
355 sidechain: AudioNodeRef,
357 },
358 UnknownComposition {
360 clip: ClipId,
362 composition: CompositionId,
364 },
365 InvalidClipComposition {
368 clip: ClipId,
370 },
371 DuplicateCompositionId(CompositionId),
373 InvalidNodeId {
376 composition: CompositionId,
378 node: NodeId,
380 },
381 DuplicateNodeId {
383 composition: CompositionId,
385 node: NodeId,
387 },
388 TooManyCompositionNodes {
390 composition: CompositionId,
392 found: usize,
394 maximum: usize,
396 },
397 InvalidNode {
401 composition: CompositionId,
403 node: NodeId,
405 },
406 UnknownNodeInput {
408 composition: CompositionId,
410 node: NodeId,
412 input: String,
414 target: NodeId,
416 },
417 CompositionCycle {
419 composition: CompositionId,
421 node: NodeId,
423 },
424 UnknownCompositionOutput {
426 composition: CompositionId,
428 node: NodeId,
430 },
431 InvalidNodeSource {
433 composition: CompositionId,
435 node: NodeId,
437 source: SourceId,
439 },
440 InvalidCompositionPorts {
443 composition: CompositionId,
445 },
446 UnknownGroupComposition {
448 composition: CompositionId,
450 node: NodeId,
452 target: CompositionId,
454 },
455 InvalidTimeOffset {
457 composition: CompositionId,
459 node: NodeId,
461 problem: crate::TimeOffsetProblem,
463 },
464 CompositionUsesItself {
466 composition: CompositionId,
468 },
469 CompositionNestedTooDeep {
472 composition: CompositionId,
474 maximum: usize,
476 },
477 TooManyInlinedNodes {
481 maximum: usize,
483 },
484 FrameDrawsTooManyNodes {
487 clip: ClipId,
489 found: u64,
491 maximum: usize,
493 },
494 InvalidCompositionSource {
497 source: SourceId,
499 },
500 InvalidAdjustmentSource {
503 source: SourceId,
505 },
506 InvalidAdjustmentTransition {
508 track: TrackId,
510 clip: ClipId,
512 },
513 InvalidEffect {
516 owner: Box<EffectOwner>,
518 id: String,
520 problem: EffectProblem,
522 },
523 UnknownNodeResource {
525 composition: CompositionId,
527 node: NodeId,
529 resource: EffectResourceId,
531 },
532 UnknownSourceResource {
534 source: SourceId,
536 resource: EffectResourceId,
538 },
539 InvalidClipMask {
542 clip: ClipId,
544 },
545 InvalidCaptions {
548 track: TrackId,
550 },
551 UnknownCaptionStyle {
553 track: TrackId,
555 cue: usize,
557 name: String,
559 },
560 InvalidCaptionCueStyle {
564 track: TrackId,
566 cue: usize,
568 },
569 InvalidTimeMap {
572 clip: ClipId,
574 problem: crate::TimeMapProblem,
576 },
577 TooManyLoopPasses {
579 clip: ClipId,
581 found: u64,
583 maximum: u64,
585 },
586 InvalidMatte {
589 clip: ClipId,
591 },
592 InvalidFrameInterpolation {
594 clip: ClipId,
596 },
597 InvalidClipTransition {
599 track: TrackId,
601 },
602 TransitionCycle {
605 track: TrackId,
607 at: alpha2_time::MediaTime,
609 },
610 DuplicateTransition {
612 track: TrackId,
614 first: ClipId,
616 second: ClipId,
618 },
619 TooManyDerivedCues {
622 track: TrackId,
624 },
625 UnwritableTime {
627 ticks: i64,
629 },
630 TooManyEffectResources {
632 found: usize,
634 maximum: usize,
636 },
637 TooManyCompositions {
639 found: usize,
641 maximum: usize,
643 },
644 TooManySources {
646 found: usize,
648 maximum: usize,
650 },
651 TooManyTracks {
653 found: usize,
655 maximum: usize,
657 },
658 TooManyClips {
660 found: usize,
662 maximum: usize,
664 },
665 TooManyAudioEffects {
668 found: usize,
670 maximum: usize,
672 at_ticks: i64,
674 },
675 TooMuchAudioDelay {
678 found_ms: u64,
680 maximum_ms: u32,
682 at_ticks: i64,
684 },
685 TooManyClipsOnTrack {
687 track: TrackId,
689 found: usize,
691 maximum: usize,
693 },
694 TooManyCaptionCues {
696 track: TrackId,
698 found: usize,
700 maximum: usize,
702 },
703 TooManyTransitions {
705 track: TrackId,
707 found: usize,
709 maximum: usize,
711 },
712 ZeroCanvasDimension,
714 CanvasDimensionTooLarge {
716 width: u32,
718 height: u32,
720 maximum: u32,
722 },
723 CanvasPixelBudgetExceeded {
725 pixels: u64,
727 maximum: u64,
729 },
730 InvalidBackground,
732 InvalidColorPipeline,
734 InvalidShutter(crate::ShutterProblem),
736 UnsupportedSampleRate {
738 found: u32,
740 minimum: u32,
742 maximum: u32,
744 },
745}
746
747#[derive(Clone, Copy, Debug, Eq, PartialEq)]
749#[non_exhaustive]
750pub enum ErrorSubject<'a> {
751 Clip(&'a ClipId),
753 Source(&'a SourceId),
755 Track(&'a TrackId),
757 Composition(&'a CompositionId),
759 DataSet(&'a DataSetId),
761 EffectResource(&'a EffectResourceId),
763 Bus(&'a BusId),
765}
766
767impl ModelError {
768 #[must_use]
772 #[expect(clippy::too_many_lines, reason = "one arm per subject")]
773 pub const fn subject(&self) -> Option<ErrorSubject<'_>> {
774 use ErrorSubject::{Bus, Clip, Composition, DataSet, EffectResource, Source, Track};
775 Some(match self {
776 Self::UnsupportedSchemaVersion { .. }
777 | Self::TooManyDataSets { .. }
778 | Self::EmptyIdentifier
779 | Self::InvalidMasterAudio
780 | Self::TooManyInlinedNodes { .. }
781 | Self::TooManyCompositions { .. }
782 | Self::TooManyEffectResources { .. }
783 | Self::UnwritableTime { .. }
784 | Self::TooManySources { .. }
785 | Self::TooManyTracks { .. }
786 | Self::TooManyClips { .. }
787 | Self::TooManyAudioEffects { .. }
788 | Self::TooMuchAudioDelay { .. }
789 | Self::TooManyAudioBuses { .. }
790 | Self::UnknownAudioSidechain { owner: None, .. }
791 | Self::ZeroCanvasDimension
792 | Self::CanvasDimensionTooLarge { .. }
793 | Self::CanvasPixelBudgetExceeded { .. }
794 | Self::InvalidBackground
795 | Self::InvalidColorPipeline
796 | Self::InvalidShutter(_)
797 | Self::UnsupportedSampleRate { .. } => return None,
798 Self::DuplicateDataSetId(data) | Self::InvalidDataSet { data, .. } => DataSet(data),
799 Self::InvalidDataBinding { owner, .. } => match owner {
800 DataOwner::Clip(clip) | DataOwner::Transition { from: clip, .. } => Clip(clip),
801 DataOwner::Track(track) => Track(track),
802 DataOwner::Master => return None,
803 DataOwner::Bus(bus) => Bus(bus),
804 DataOwner::Node { composition, .. } => Composition(composition),
805 DataOwner::Source(source) => Source(source),
806 },
807 Self::InvalidShape { owner, .. }
808 | Self::InvalidLayout { owner, .. }
809 | Self::InvalidTextRunStyle { owner, .. } => match owner {
810 ShapeOwner::Source(source) => Source(source),
811 ShapeOwner::Clip(clip) => Clip(clip),
812 ShapeOwner::Node { composition, .. } => Composition(composition),
813 },
814 Self::InvalidEffect { owner, .. } => match &**owner {
815 EffectOwner::Node { composition, .. } => Composition(composition),
816 EffectOwner::Transition { from, .. } => Clip(from),
817 EffectOwner::Source(source) => Source(source),
818 },
819 Self::DuplicateSourceId(source)
820 | Self::EmptyLocator { source }
821 | Self::AudioOnImage { source }
822 | Self::InvalidProvider { source }
823 | Self::InvalidFingerprint { source }
824 | Self::ContradictoryColor { source }
825 | Self::InvalidGenerator { source }
826 | Self::UnknownSourceResource { source, .. }
827 | Self::InvalidCompositionSource { source }
828 | Self::InvalidAdjustmentSource { source } => Source(source),
829 Self::DuplicateEffectResourceId(resource)
830 | Self::EmptyEffectResourceLocator { resource } => EffectResource(resource),
831 Self::InvalidAudioBus { bus } | Self::DuplicateAudioBus { bus } => Bus(bus),
832 Self::InvalidAudioSend { from: node, .. }
833 | Self::UnknownAudioBus { from: node, .. }
834 | Self::UnknownAudioSidechain {
835 owner: Some(node), ..
836 }
837 | Self::AudioRoutingCycle { node } => match node {
838 AudioNodeRef::Track(track) => Track(track),
839 AudioNodeRef::Bus(bus) => Bus(bus),
840 },
841 Self::DuplicateTrackId(track)
842 | Self::InvalidTrackAudio { track }
843 | Self::InvalidCaptions { track }
844 | Self::UnknownCaptionStyle { track, .. }
845 | Self::InvalidCaptionCueStyle { track, .. }
846 | Self::InvalidClipTransition { track }
847 | Self::TransitionCycle { track, .. }
848 | Self::DuplicateTransition { track, .. }
849 | Self::TooManyClipsOnTrack { track, .. }
850 | Self::TooManyCaptionCues { track, .. }
851 | Self::TooManyDerivedCues { track }
852 | Self::TooManyTransitions { track, .. } => Track(track),
853 Self::DuplicateClipId(clip)
854 | Self::UnknownEffectResource { clip, .. }
855 | Self::EmptyClipRange { clip }
856 | Self::NegativeClipRange { clip }
857 | Self::OverlappingClips { second: clip, .. }
858 | Self::UnknownClipSource { clip, .. }
859 | Self::IncompatibleClipSource { clip, .. }
860 | Self::InvalidVisualProperties { clip }
861 | Self::InvalidAudioProperties { clip }
862 | Self::UnknownComposition { clip, .. }
863 | Self::InvalidClipComposition { clip }
864 | Self::FrameDrawsTooManyNodes { clip, .. }
865 | Self::InvalidClipMask { clip }
866 | Self::InvalidTimeMap { clip, .. }
867 | Self::TooManyLoopPasses { clip, .. }
868 | Self::InvalidAdjustmentTransition { clip, .. }
869 | Self::InvalidMatte { clip }
870 | Self::InvalidFrameInterpolation { clip } => Clip(clip),
871 Self::DuplicateCompositionId(composition)
872 | Self::InvalidNodeId { composition, .. }
873 | Self::DuplicateNodeId { composition, .. }
874 | Self::TooManyCompositionNodes { composition, .. }
875 | Self::InvalidNode { composition, .. }
876 | Self::UnknownNodeInput { composition, .. }
877 | Self::CompositionCycle { composition, .. }
878 | Self::UnknownCompositionOutput { composition, .. }
879 | Self::InvalidNodeSource { composition, .. }
880 | Self::InvalidCompositionPorts { composition }
881 | Self::UnknownGroupComposition { composition, .. }
882 | Self::InvalidTimeOffset { composition, .. }
883 | Self::CompositionUsesItself { composition }
884 | Self::CompositionNestedTooDeep { composition, .. }
885 | Self::UnknownNodeResource { composition, .. } => Composition(composition),
886 })
887 }
888
889 #[must_use]
891 pub const fn code(&self) -> &'static alpha2_diagnose::Code {
892 crate::diagnose::codes::model_error_code(self)
893 }
894}
895
896impl fmt::Display for ModelError {
897 #[allow(clippy::too_many_lines)]
898 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
899 match self {
900 Self::UnsupportedSchemaVersion { found } => {
901 write!(formatter, "unsupported schema version {found}")
902 }
903 Self::EmptyIdentifier => formatter.write_str("document contains an empty identifier"),
904 Self::DuplicateSourceId(id) => write!(formatter, "duplicate source ID {id}"),
905 Self::DuplicateEffectResourceId(id) => {
906 write!(formatter, "duplicate effect resource ID {id}")
907 }
908 Self::DuplicateTrackId(id) => write!(formatter, "duplicate track ID {id}"),
909 Self::DuplicateClipId(id) => write!(formatter, "duplicate clip ID {id}"),
910 Self::EmptyLocator { source } => {
911 write!(formatter, "source {source} has an empty locator")
912 }
913 Self::AudioOnImage { source } => {
914 write!(
915 formatter,
916 "source {source} is a still image and has no audio"
917 )
918 }
919 Self::InvalidGenerator { source } => {
920 write!(formatter, "source {source} has an invalid generator")
921 }
922 Self::InvalidShape { owner, at, problem } => {
923 write!(formatter, "{owner} has an invalid shape: {at} {problem}")
924 }
925 Self::InvalidLayout { owner, at, problem } => {
926 write!(formatter, "{owner} has an invalid layout: {at} {problem}")
927 }
928 Self::InvalidTextRunStyle { owner, run } => {
929 write!(
930 formatter,
931 "{owner} has text run {run} with a style out of range"
932 )
933 }
934 Self::ContradictoryColor { source } => write!(
935 formatter,
936 "source {source} declares a dynamic range its transfer contradicts"
937 ),
938 Self::InvalidFingerprint { source } => {
939 write!(formatter, "source {source} has an invalid fingerprint")
940 }
941 Self::InvalidProvider { source } => {
942 write!(formatter, "source {source} has an invalid provider")
943 }
944 Self::EmptyEffectResourceLocator { resource } => {
945 write!(formatter, "effect resource {resource} has an empty locator")
946 }
947 Self::UnknownEffectResource { clip, resource } => {
948 write!(
949 formatter,
950 "clip {clip} references unknown effect resource {resource}"
951 )
952 }
953 Self::EmptyClipRange { clip } => write!(formatter, "clip {clip} has an empty range"),
954 Self::NegativeClipRange { clip } => {
955 write!(formatter, "clip {clip} has a range before timeline origin")
956 }
957 Self::OverlappingClips {
958 track,
959 first,
960 second,
961 } => write!(
962 formatter,
963 "clips {first} and {second} overlap without a covering transition on track {track}"
964 ),
965 Self::UnknownClipSource { clip, source } => {
966 write!(formatter, "clip {clip} references unknown source {source}")
967 }
968 Self::IncompatibleClipSource {
969 clip,
970 track,
971 source,
972 } => {
973 write!(
974 formatter,
975 "clip {clip} cannot use source {source} on track {track}"
976 )
977 }
978 Self::InvalidVisualProperties { clip } => {
979 write!(formatter, "clip {clip} has invalid visual properties")
980 }
981 Self::InvalidAudioProperties { clip } => {
982 write!(formatter, "clip {clip} has invalid audio properties")
983 }
984 Self::InvalidTrackAudio { track } => {
985 write!(formatter, "track {track} has invalid audio bus settings")
986 }
987 Self::InvalidMasterAudio => {
988 write!(formatter, "the project master bus is invalid")
989 }
990 Self::InvalidAudioBus { bus } => {
991 write!(formatter, "bus {bus} has invalid audio bus settings")
992 }
993 Self::InvalidAudioSend { from, to } => {
994 write!(formatter, "{from} has an invalid send to bus {to}")
995 }
996 Self::UnknownAudioBus { from, bus } => {
997 write!(formatter, "{from} routes to unknown bus {bus}")
998 }
999 Self::DuplicateAudioBus { bus } => write!(formatter, "duplicate bus id {bus}"),
1000 Self::AudioRoutingCycle { node } => {
1001 write!(formatter, "{node} is on an audio routing cycle")
1002 }
1003 Self::TooManyAudioBuses { found, maximum } => {
1004 write!(
1005 formatter,
1006 "project has {found} audio buses; the maximum is {maximum}"
1007 )
1008 }
1009 Self::UnknownAudioSidechain {
1010 owner: Some(owner),
1011 sidechain,
1012 } => write!(formatter, "{owner} keys an effect from unknown {sidechain}"),
1013 Self::UnknownAudioSidechain {
1014 owner: None,
1015 sidechain,
1016 } => write!(
1017 formatter,
1018 "the master bus keys an effect from unknown {sidechain}"
1019 ),
1020 Self::UnknownComposition { clip, composition } => {
1021 write!(
1022 formatter,
1023 "clip {clip} references unknown composition {composition}"
1024 )
1025 }
1026 Self::InvalidClipComposition { clip } => {
1027 write!(
1028 formatter,
1029 "clip {clip} has an invalid composition reference"
1030 )
1031 }
1032 Self::DuplicateCompositionId(id) => write!(formatter, "duplicate composition ID {id}"),
1033 Self::InvalidNodeId { composition, node } => {
1034 write!(
1035 formatter,
1036 "composition {composition} has node ID {node}, which has a `/`"
1037 )
1038 }
1039 Self::DuplicateNodeId { composition, node } => {
1040 write!(
1041 formatter,
1042 "composition {composition} has duplicate node ID {node}"
1043 )
1044 }
1045 Self::TooManyCompositionNodes {
1046 composition,
1047 found,
1048 maximum,
1049 } => write!(
1050 formatter,
1051 "composition {composition} has {found} nodes; the maximum is {maximum}"
1052 ),
1053 Self::InvalidNode { composition, node } => {
1054 write!(
1055 formatter,
1056 "node {node} of composition {composition} has an invalid setting"
1057 )
1058 }
1059 Self::UnknownNodeInput {
1060 composition,
1061 node,
1062 input,
1063 target,
1064 } => write!(
1065 formatter,
1066 "input {input} of node {node} in composition {composition} names unknown node {target}"
1067 ),
1068 Self::CompositionCycle { composition, node } => write!(
1069 formatter,
1070 "node {node} of composition {composition} depends on its own output"
1071 ),
1072 Self::UnknownCompositionOutput { composition, node } => write!(
1073 formatter,
1074 "composition {composition} outputs unknown node {node}"
1075 ),
1076 Self::InvalidNodeSource {
1077 composition,
1078 node,
1079 source,
1080 } => write!(
1081 formatter,
1082 "node {node} of composition {composition} cannot show source {source}"
1083 ),
1084 Self::InvalidCompositionPorts { composition } => write!(
1085 formatter,
1086 "composition {composition} has invalid group inputs or controls"
1087 ),
1088 Self::UnknownGroupComposition {
1089 composition,
1090 node,
1091 target,
1092 } => write!(
1093 formatter,
1094 "group node {node} of composition {composition} names unknown composition {target}"
1095 ),
1096 Self::InvalidTimeOffset {
1097 composition,
1098 node,
1099 problem,
1100 } => write!(
1101 formatter,
1102 "time offset node {node} of composition {composition} {problem}"
1103 ),
1104 Self::CompositionUsesItself { composition } => {
1105 write!(formatter, "composition {composition} uses itself")
1106 }
1107 Self::CompositionNestedTooDeep {
1108 composition,
1109 maximum,
1110 } => write!(
1111 formatter,
1112 "composition {composition} nests compositions and time offsets more than {maximum} deep"
1113 ),
1114 Self::TooManyInlinedNodes { maximum } => write!(
1115 formatter,
1116 "compositions draw more than {maximum} nodes, counting each group and composition source as the nodes it draws and each time offset as the nodes it draws again"
1117 ),
1118 Self::FrameDrawsTooManyNodes {
1119 clip,
1120 found,
1121 maximum,
1122 } => write!(
1123 formatter,
1124 "the clips on the timeline where clip {clip} starts draw {found} composition nodes; a frame draws at most {maximum}"
1125 ),
1126 Self::InvalidCompositionSource { source } => {
1127 write!(
1128 formatter,
1129 "source {source} is not a valid composition source"
1130 )
1131 }
1132 Self::InvalidAdjustmentSource { source } => write!(
1133 formatter,
1134 "source {source} is not a valid adjustment source: it has only an id and its kind"
1135 ),
1136 Self::InvalidAdjustmentTransition { track, clip } => write!(
1137 formatter,
1138 "a transition on track {track} names adjustment clip {clip}, which only fades"
1139 ),
1140 Self::InvalidEffect { owner, id, problem } => {
1141 write!(formatter, "effect {id} in {owner} {problem}")
1142 }
1143 Self::UnknownNodeResource {
1144 composition,
1145 node,
1146 resource,
1147 } => write!(
1148 formatter,
1149 "node {node} of composition {composition} references unknown effect resource {resource}"
1150 ),
1151 Self::UnknownSourceResource { source, resource } => write!(
1152 formatter,
1153 "source {source} references unknown effect resource {resource}"
1154 ),
1155 Self::InvalidClipMask { clip } => write!(formatter, "clip {clip} has an invalid mask"),
1156 Self::InvalidMatte { clip } => write!(formatter, "clip {clip} has an invalid matte"),
1157 Self::InvalidFrameInterpolation { clip } => write!(
1158 formatter,
1159 "clip {clip} sets a frame interpolation outside a video track"
1160 ),
1161 Self::InvalidCaptions { track } => {
1162 write!(formatter, "track {track} has invalid captions")
1163 }
1164 Self::UnknownCaptionStyle { track, cue, name } => write!(
1165 formatter,
1166 "cue {cue} of track {track} names style {name:?}, which the track does not have"
1167 ),
1168 Self::InvalidCaptionCueStyle { track, cue } => write!(
1169 formatter,
1170 "cue {cue} of track {track} has a style out of range once its patch is applied"
1171 ),
1172 Self::InvalidTimeMap { clip, problem } => {
1173 use crate::TimeMapProblem as Problem;
1174 match problem {
1175 Problem::FreezeOutsideSource => {
1176 write!(formatter, "clip {clip} freezes outside its source range")
1177 }
1178 Problem::KeyframeCount { found } => write!(
1179 formatter,
1180 "the time curve of clip {clip} takes 2 to {} keyframes, not {found}",
1181 crate::MAX_KEYFRAMES
1182 ),
1183 Problem::TimeOrder { keyframe } => write!(
1184 formatter,
1185 "keyframe {keyframe} of clip {clip}'s time curve is not after the one \
1186 before it"
1187 ),
1188 Problem::OutsideSource { keyframe } => write!(
1189 formatter,
1190 "keyframe {keyframe} of clip {clip}'s time curve is outside its source \
1191 range"
1192 ),
1193 Problem::Interpolation { keyframe } => write!(
1194 formatter,
1195 "keyframe {keyframe} of clip {clip}'s time curve has an invalid \
1196 interpolation"
1197 ),
1198 Problem::Passes { found } => write!(
1199 formatter,
1200 "clip {clip}'s time curve plays {found} segments; the maximum is {}",
1201 crate::MAX_KEYFRAMES
1202 ),
1203 }
1204 }
1205 Self::TooManyLoopPasses {
1206 clip,
1207 found,
1208 maximum,
1209 } => write!(
1210 formatter,
1211 "clip {clip} loops {found} times; the maximum is {maximum}"
1212 ),
1213 Self::InvalidClipTransition { track } => {
1214 write!(formatter, "track {track} has an invalid clip transition")
1215 }
1216 Self::TransitionCycle { track, at } => write!(
1217 formatter,
1218 "transitions on track {track} active at {} ticks lead from clip to clip in a circle",
1219 at.ticks()
1220 ),
1221 Self::DuplicateTransition {
1222 track,
1223 first,
1224 second,
1225 } => write!(
1226 formatter,
1227 "clips {first} and {second} have more than one transition on track {track}"
1228 ),
1229 Self::TooManyDerivedCues { track } => write!(
1230 formatter,
1231 "track {track} derives more than {} caption cues or maps more than {} words",
1232 crate::MAX_DERIVED_CUES,
1233 crate::MAX_DATA_WORDS
1234 ),
1235 Self::UnwritableTime { ticks } => write!(
1236 formatter,
1237 "a time of {ticks} ticks is beyond {} either way",
1238 alpha2_time::MAX_SERIALIZED_TICKS
1239 ),
1240 Self::TooManyEffectResources { found, maximum } => write!(
1241 formatter,
1242 "project has {found} effect resources; the maximum is {maximum}"
1243 ),
1244 Self::TooManyCompositions { found, maximum } => write!(
1245 formatter,
1246 "project has {found} compositions; the maximum is {maximum}"
1247 ),
1248 Self::TooManySources { found, maximum } => {
1249 write!(
1250 formatter,
1251 "project has {found} sources; the maximum is {maximum}"
1252 )
1253 }
1254 Self::TooManyTracks { found, maximum } => {
1255 write!(
1256 formatter,
1257 "project has {found} tracks; the maximum is {maximum}"
1258 )
1259 }
1260 Self::TooManyClips { found, maximum } => {
1261 write!(
1262 formatter,
1263 "project has {found} clips; the maximum is {maximum}"
1264 )
1265 }
1266 Self::TooManyAudioEffects {
1267 found,
1268 maximum,
1269 at_ticks,
1270 } => write!(
1271 formatter,
1272 "project has {found} audio effects holding state at tick {at_ticks}; the maximum at once is {maximum}"
1273 ),
1274 Self::TooMuchAudioDelay {
1275 found_ms,
1276 maximum_ms,
1277 at_ticks,
1278 } => write!(
1279 formatter,
1280 "project audio effects hold {found_ms} ms of delay at tick {at_ticks}; the maximum at once is {maximum_ms} ms"
1281 ),
1282 Self::TooManyClipsOnTrack {
1283 track,
1284 found,
1285 maximum,
1286 } => write!(
1287 formatter,
1288 "track {track} has {found} clips; the maximum is {maximum}"
1289 ),
1290 Self::TooManyCaptionCues {
1291 track,
1292 found,
1293 maximum,
1294 } => write!(
1295 formatter,
1296 "track {track} has {found} caption cues; the maximum is {maximum}"
1297 ),
1298 Self::TooManyTransitions {
1299 track,
1300 found,
1301 maximum,
1302 } => write!(
1303 formatter,
1304 "track {track} has {found} transitions; the maximum is {maximum}"
1305 ),
1306 Self::ZeroCanvasDimension => formatter.write_str("canvas dimensions must be positive"),
1307 Self::CanvasDimensionTooLarge {
1308 width,
1309 height,
1310 maximum,
1311 } => write!(
1312 formatter,
1313 "canvas {width}x{height} exceeds the maximum edge {maximum}"
1314 ),
1315 Self::CanvasPixelBudgetExceeded { pixels, maximum } => write!(
1316 formatter,
1317 "canvas has {pixels} pixels; the maximum is {maximum}"
1318 ),
1319 Self::InvalidBackground => {
1320 formatter.write_str("background color components must be finite and within 0..=1")
1321 }
1322 Self::InvalidColorPipeline => {
1323 formatter.write_str("the HDR peak must be within 100..=10000 nits")
1324 }
1325 Self::InvalidShutter(problem) => problem.fmt(formatter),
1326 Self::TooManyDataSets { found, maximum } => write!(
1327 formatter,
1328 "project has {found} data sets; the maximum is {maximum}"
1329 ),
1330 Self::DuplicateDataSetId(data) => write!(formatter, "duplicate data set id {data}"),
1331 Self::InvalidDataSet { data, problem } => {
1332 write!(formatter, "data set {data} {problem}")
1333 }
1334 Self::InvalidDataBinding { owner, at, problem } => {
1335 write!(formatter, "{owner} {at} {problem}")
1336 }
1337 Self::UnsupportedSampleRate {
1338 found,
1339 minimum,
1340 maximum,
1341 } => write!(
1342 formatter,
1343 "sample rate {found} is outside {minimum}..={maximum}"
1344 ),
1345 }
1346 }
1347}
1348
1349impl std::error::Error for ModelError {}
1350
1351#[derive(Debug)]
1353#[non_exhaustive]
1354pub enum ProjectLoadError {
1355 TooLarge {
1357 bytes: usize,
1359 maximum: usize,
1361 },
1362 Json(serde_json::Error),
1364 InvalidProject(ModelError),
1366}
1367
1368impl fmt::Display for ProjectLoadError {
1369 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1370 match self {
1371 Self::TooLarge { bytes, maximum } => {
1372 write!(
1373 formatter,
1374 "project JSON is {bytes} bytes; the maximum is {maximum}"
1375 )
1376 }
1377 Self::Json(error) => write!(formatter, "invalid project JSON: {error}"),
1378 Self::InvalidProject(error) => write!(formatter, "invalid project: {error}"),
1379 }
1380 }
1381}
1382
1383impl std::error::Error for ProjectLoadError {
1384 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1385 match self {
1386 Self::TooLarge { .. } => None,
1387 Self::Json(error) => Some(error),
1388 Self::InvalidProject(error) => Some(error),
1389 }
1390 }
1391}
1392
1393#[derive(Debug)]
1395#[non_exhaustive]
1396pub enum ProjectWriteError {
1397 TooLarge {
1399 maximum: usize,
1401 },
1402 Json(serde_json::Error),
1404}
1405
1406impl fmt::Display for ProjectWriteError {
1407 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1408 match self {
1409 Self::TooLarge { maximum } => write!(
1410 formatter,
1411 "the project JSON would be longer than {maximum} bytes, the maximum a project loads with"
1412 ),
1413 Self::Json(error) => write!(formatter, "the project does not serialize: {error}"),
1414 }
1415 }
1416}
1417
1418impl std::error::Error for ProjectWriteError {
1419 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1420 match self {
1421 Self::TooLarge { .. } => None,
1422 Self::Json(error) => Some(error),
1423 }
1424 }
1425}