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
890impl fmt::Display for ModelError {
891 #[allow(clippy::too_many_lines)]
892 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
893 match self {
894 Self::UnsupportedSchemaVersion { found } => {
895 write!(formatter, "unsupported schema version {found}")
896 }
897 Self::EmptyIdentifier => formatter.write_str("document contains an empty identifier"),
898 Self::DuplicateSourceId(id) => write!(formatter, "duplicate source ID {id}"),
899 Self::DuplicateEffectResourceId(id) => {
900 write!(formatter, "duplicate effect resource ID {id}")
901 }
902 Self::DuplicateTrackId(id) => write!(formatter, "duplicate track ID {id}"),
903 Self::DuplicateClipId(id) => write!(formatter, "duplicate clip ID {id}"),
904 Self::EmptyLocator { source } => {
905 write!(formatter, "source {source} has an empty locator")
906 }
907 Self::AudioOnImage { source } => {
908 write!(
909 formatter,
910 "source {source} is a still image and has no audio"
911 )
912 }
913 Self::InvalidGenerator { source } => {
914 write!(formatter, "source {source} has an invalid generator")
915 }
916 Self::InvalidShape { owner, at, problem } => {
917 write!(formatter, "{owner} has an invalid shape: {at} {problem}")
918 }
919 Self::InvalidLayout { owner, at, problem } => {
920 write!(formatter, "{owner} has an invalid layout: {at} {problem}")
921 }
922 Self::InvalidTextRunStyle { owner, run } => {
923 write!(
924 formatter,
925 "{owner} has text run {run} with a style out of range"
926 )
927 }
928 Self::ContradictoryColor { source } => write!(
929 formatter,
930 "source {source} declares a dynamic range its transfer contradicts"
931 ),
932 Self::InvalidFingerprint { source } => {
933 write!(formatter, "source {source} has an invalid fingerprint")
934 }
935 Self::InvalidProvider { source } => {
936 write!(formatter, "source {source} has an invalid provider")
937 }
938 Self::EmptyEffectResourceLocator { resource } => {
939 write!(formatter, "effect resource {resource} has an empty locator")
940 }
941 Self::UnknownEffectResource { clip, resource } => {
942 write!(
943 formatter,
944 "clip {clip} references unknown effect resource {resource}"
945 )
946 }
947 Self::EmptyClipRange { clip } => write!(formatter, "clip {clip} has an empty range"),
948 Self::NegativeClipRange { clip } => {
949 write!(formatter, "clip {clip} has a range before timeline origin")
950 }
951 Self::OverlappingClips {
952 track,
953 first,
954 second,
955 } => write!(
956 formatter,
957 "clips {first} and {second} overlap without a covering transition on track {track}"
958 ),
959 Self::UnknownClipSource { clip, source } => {
960 write!(formatter, "clip {clip} references unknown source {source}")
961 }
962 Self::IncompatibleClipSource {
963 clip,
964 track,
965 source,
966 } => {
967 write!(
968 formatter,
969 "clip {clip} cannot use source {source} on track {track}"
970 )
971 }
972 Self::InvalidVisualProperties { clip } => {
973 write!(formatter, "clip {clip} has invalid visual properties")
974 }
975 Self::InvalidAudioProperties { clip } => {
976 write!(formatter, "clip {clip} has invalid audio properties")
977 }
978 Self::InvalidTrackAudio { track } => {
979 write!(formatter, "track {track} has invalid audio bus settings")
980 }
981 Self::InvalidMasterAudio => {
982 write!(formatter, "the project master bus is invalid")
983 }
984 Self::InvalidAudioBus { bus } => {
985 write!(formatter, "bus {bus} has invalid audio bus settings")
986 }
987 Self::InvalidAudioSend { from, to } => {
988 write!(formatter, "{from} has an invalid send to bus {to}")
989 }
990 Self::UnknownAudioBus { from, bus } => {
991 write!(formatter, "{from} routes to unknown bus {bus}")
992 }
993 Self::DuplicateAudioBus { bus } => write!(formatter, "duplicate bus id {bus}"),
994 Self::AudioRoutingCycle { node } => {
995 write!(formatter, "{node} is on an audio routing cycle")
996 }
997 Self::TooManyAudioBuses { found, maximum } => {
998 write!(
999 formatter,
1000 "project has {found} audio buses; the maximum is {maximum}"
1001 )
1002 }
1003 Self::UnknownAudioSidechain {
1004 owner: Some(owner),
1005 sidechain,
1006 } => write!(formatter, "{owner} keys an effect from unknown {sidechain}"),
1007 Self::UnknownAudioSidechain {
1008 owner: None,
1009 sidechain,
1010 } => write!(
1011 formatter,
1012 "the master bus keys an effect from unknown {sidechain}"
1013 ),
1014 Self::UnknownComposition { clip, composition } => {
1015 write!(
1016 formatter,
1017 "clip {clip} references unknown composition {composition}"
1018 )
1019 }
1020 Self::InvalidClipComposition { clip } => {
1021 write!(
1022 formatter,
1023 "clip {clip} has an invalid composition reference"
1024 )
1025 }
1026 Self::DuplicateCompositionId(id) => write!(formatter, "duplicate composition ID {id}"),
1027 Self::InvalidNodeId { composition, node } => {
1028 write!(
1029 formatter,
1030 "composition {composition} has node ID {node}, which has a `/`"
1031 )
1032 }
1033 Self::DuplicateNodeId { composition, node } => {
1034 write!(
1035 formatter,
1036 "composition {composition} has duplicate node ID {node}"
1037 )
1038 }
1039 Self::TooManyCompositionNodes {
1040 composition,
1041 found,
1042 maximum,
1043 } => write!(
1044 formatter,
1045 "composition {composition} has {found} nodes; the maximum is {maximum}"
1046 ),
1047 Self::InvalidNode { composition, node } => {
1048 write!(
1049 formatter,
1050 "node {node} of composition {composition} has an invalid setting"
1051 )
1052 }
1053 Self::UnknownNodeInput {
1054 composition,
1055 node,
1056 input,
1057 target,
1058 } => write!(
1059 formatter,
1060 "input {input} of node {node} in composition {composition} names unknown node {target}"
1061 ),
1062 Self::CompositionCycle { composition, node } => write!(
1063 formatter,
1064 "node {node} of composition {composition} depends on its own output"
1065 ),
1066 Self::UnknownCompositionOutput { composition, node } => write!(
1067 formatter,
1068 "composition {composition} outputs unknown node {node}"
1069 ),
1070 Self::InvalidNodeSource {
1071 composition,
1072 node,
1073 source,
1074 } => write!(
1075 formatter,
1076 "node {node} of composition {composition} cannot show source {source}"
1077 ),
1078 Self::InvalidCompositionPorts { composition } => write!(
1079 formatter,
1080 "composition {composition} has invalid group inputs or controls"
1081 ),
1082 Self::UnknownGroupComposition {
1083 composition,
1084 node,
1085 target,
1086 } => write!(
1087 formatter,
1088 "group node {node} of composition {composition} names unknown composition {target}"
1089 ),
1090 Self::InvalidTimeOffset {
1091 composition,
1092 node,
1093 problem,
1094 } => write!(
1095 formatter,
1096 "time offset node {node} of composition {composition} {problem}"
1097 ),
1098 Self::CompositionUsesItself { composition } => {
1099 write!(formatter, "composition {composition} uses itself")
1100 }
1101 Self::CompositionNestedTooDeep {
1102 composition,
1103 maximum,
1104 } => write!(
1105 formatter,
1106 "composition {composition} nests compositions and time offsets more than {maximum} deep"
1107 ),
1108 Self::TooManyInlinedNodes { maximum } => write!(
1109 formatter,
1110 "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"
1111 ),
1112 Self::FrameDrawsTooManyNodes {
1113 clip,
1114 found,
1115 maximum,
1116 } => write!(
1117 formatter,
1118 "the clips on the timeline where clip {clip} starts draw {found} composition nodes; a frame draws at most {maximum}"
1119 ),
1120 Self::InvalidCompositionSource { source } => {
1121 write!(
1122 formatter,
1123 "source {source} is not a valid composition source"
1124 )
1125 }
1126 Self::InvalidAdjustmentSource { source } => write!(
1127 formatter,
1128 "source {source} is not a valid adjustment source: it has only an id and its kind"
1129 ),
1130 Self::InvalidAdjustmentTransition { track, clip } => write!(
1131 formatter,
1132 "a transition on track {track} names adjustment clip {clip}, which only fades"
1133 ),
1134 Self::InvalidEffect { owner, id, problem } => {
1135 write!(formatter, "effect {id} in {owner} {problem}")
1136 }
1137 Self::UnknownNodeResource {
1138 composition,
1139 node,
1140 resource,
1141 } => write!(
1142 formatter,
1143 "node {node} of composition {composition} references unknown effect resource {resource}"
1144 ),
1145 Self::UnknownSourceResource { source, resource } => write!(
1146 formatter,
1147 "source {source} references unknown effect resource {resource}"
1148 ),
1149 Self::InvalidClipMask { clip } => write!(formatter, "clip {clip} has an invalid mask"),
1150 Self::InvalidMatte { clip } => write!(formatter, "clip {clip} has an invalid matte"),
1151 Self::InvalidFrameInterpolation { clip } => write!(
1152 formatter,
1153 "clip {clip} sets a frame interpolation outside a video track"
1154 ),
1155 Self::InvalidCaptions { track } => {
1156 write!(formatter, "track {track} has invalid captions")
1157 }
1158 Self::UnknownCaptionStyle { track, cue, name } => write!(
1159 formatter,
1160 "cue {cue} of track {track} names style {name:?}, which the track does not have"
1161 ),
1162 Self::InvalidCaptionCueStyle { track, cue } => write!(
1163 formatter,
1164 "cue {cue} of track {track} has a style out of range once its patch is applied"
1165 ),
1166 Self::InvalidTimeMap { clip, problem } => {
1167 use crate::TimeMapProblem as Problem;
1168 match problem {
1169 Problem::FreezeOutsideSource => {
1170 write!(formatter, "clip {clip} freezes outside its source range")
1171 }
1172 Problem::KeyframeCount { found } => write!(
1173 formatter,
1174 "the time curve of clip {clip} takes 2 to {} keyframes, not {found}",
1175 crate::MAX_KEYFRAMES
1176 ),
1177 Problem::TimeOrder { keyframe } => write!(
1178 formatter,
1179 "keyframe {keyframe} of clip {clip}'s time curve is not after the one \
1180 before it"
1181 ),
1182 Problem::OutsideSource { keyframe } => write!(
1183 formatter,
1184 "keyframe {keyframe} of clip {clip}'s time curve is outside its source \
1185 range"
1186 ),
1187 Problem::Interpolation { keyframe } => write!(
1188 formatter,
1189 "keyframe {keyframe} of clip {clip}'s time curve has an invalid \
1190 interpolation"
1191 ),
1192 Problem::Passes { found } => write!(
1193 formatter,
1194 "clip {clip}'s time curve plays {found} segments; the maximum is {}",
1195 crate::MAX_KEYFRAMES
1196 ),
1197 }
1198 }
1199 Self::TooManyLoopPasses {
1200 clip,
1201 found,
1202 maximum,
1203 } => write!(
1204 formatter,
1205 "clip {clip} loops {found} times; the maximum is {maximum}"
1206 ),
1207 Self::InvalidClipTransition { track } => {
1208 write!(formatter, "track {track} has an invalid clip transition")
1209 }
1210 Self::TransitionCycle { track, at } => write!(
1211 formatter,
1212 "transitions on track {track} active at {} ticks lead from clip to clip in a circle",
1213 at.ticks()
1214 ),
1215 Self::DuplicateTransition {
1216 track,
1217 first,
1218 second,
1219 } => write!(
1220 formatter,
1221 "clips {first} and {second} have more than one transition on track {track}"
1222 ),
1223 Self::TooManyDerivedCues { track } => write!(
1224 formatter,
1225 "track {track} derives more than {} caption cues or maps more than {} words",
1226 crate::MAX_DERIVED_CUES,
1227 crate::MAX_DATA_WORDS
1228 ),
1229 Self::UnwritableTime { ticks } => write!(
1230 formatter,
1231 "a time of {ticks} ticks is beyond {} either way",
1232 alpha2_time::MAX_SERIALIZED_TICKS
1233 ),
1234 Self::TooManyEffectResources { found, maximum } => write!(
1235 formatter,
1236 "project has {found} effect resources; the maximum is {maximum}"
1237 ),
1238 Self::TooManyCompositions { found, maximum } => write!(
1239 formatter,
1240 "project has {found} compositions; the maximum is {maximum}"
1241 ),
1242 Self::TooManySources { found, maximum } => {
1243 write!(
1244 formatter,
1245 "project has {found} sources; the maximum is {maximum}"
1246 )
1247 }
1248 Self::TooManyTracks { found, maximum } => {
1249 write!(
1250 formatter,
1251 "project has {found} tracks; the maximum is {maximum}"
1252 )
1253 }
1254 Self::TooManyClips { found, maximum } => {
1255 write!(
1256 formatter,
1257 "project has {found} clips; the maximum is {maximum}"
1258 )
1259 }
1260 Self::TooManyAudioEffects {
1261 found,
1262 maximum,
1263 at_ticks,
1264 } => write!(
1265 formatter,
1266 "project has {found} audio effects holding state at tick {at_ticks}; the maximum at once is {maximum}"
1267 ),
1268 Self::TooMuchAudioDelay {
1269 found_ms,
1270 maximum_ms,
1271 at_ticks,
1272 } => write!(
1273 formatter,
1274 "project audio effects hold {found_ms} ms of delay at tick {at_ticks}; the maximum at once is {maximum_ms} ms"
1275 ),
1276 Self::TooManyClipsOnTrack {
1277 track,
1278 found,
1279 maximum,
1280 } => write!(
1281 formatter,
1282 "track {track} has {found} clips; the maximum is {maximum}"
1283 ),
1284 Self::TooManyCaptionCues {
1285 track,
1286 found,
1287 maximum,
1288 } => write!(
1289 formatter,
1290 "track {track} has {found} caption cues; the maximum is {maximum}"
1291 ),
1292 Self::TooManyTransitions {
1293 track,
1294 found,
1295 maximum,
1296 } => write!(
1297 formatter,
1298 "track {track} has {found} transitions; the maximum is {maximum}"
1299 ),
1300 Self::ZeroCanvasDimension => formatter.write_str("canvas dimensions must be positive"),
1301 Self::CanvasDimensionTooLarge {
1302 width,
1303 height,
1304 maximum,
1305 } => write!(
1306 formatter,
1307 "canvas {width}x{height} exceeds the maximum edge {maximum}"
1308 ),
1309 Self::CanvasPixelBudgetExceeded { pixels, maximum } => write!(
1310 formatter,
1311 "canvas has {pixels} pixels; the maximum is {maximum}"
1312 ),
1313 Self::InvalidBackground => {
1314 formatter.write_str("background color components must be finite and within 0..=1")
1315 }
1316 Self::InvalidColorPipeline => {
1317 formatter.write_str("the HDR peak must be within 100..=10000 nits")
1318 }
1319 Self::InvalidShutter(problem) => problem.fmt(formatter),
1320 Self::TooManyDataSets { found, maximum } => write!(
1321 formatter,
1322 "project has {found} data sets; the maximum is {maximum}"
1323 ),
1324 Self::DuplicateDataSetId(data) => write!(formatter, "duplicate data set id {data}"),
1325 Self::InvalidDataSet { data, problem } => {
1326 write!(formatter, "data set {data} {problem}")
1327 }
1328 Self::InvalidDataBinding { owner, at, problem } => {
1329 write!(formatter, "{owner} {at} {problem}")
1330 }
1331 Self::UnsupportedSampleRate {
1332 found,
1333 minimum,
1334 maximum,
1335 } => write!(
1336 formatter,
1337 "sample rate {found} is outside {minimum}..={maximum}"
1338 ),
1339 }
1340 }
1341}
1342
1343impl std::error::Error for ModelError {}
1344
1345#[derive(Debug)]
1347#[non_exhaustive]
1348pub enum ProjectLoadError {
1349 TooLarge {
1351 bytes: usize,
1353 maximum: usize,
1355 },
1356 Json(serde_json::Error),
1358 InvalidProject(ModelError),
1360}
1361
1362impl fmt::Display for ProjectLoadError {
1363 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1364 match self {
1365 Self::TooLarge { bytes, maximum } => {
1366 write!(
1367 formatter,
1368 "project JSON is {bytes} bytes; the maximum is {maximum}"
1369 )
1370 }
1371 Self::Json(error) => write!(formatter, "invalid project JSON: {error}"),
1372 Self::InvalidProject(error) => write!(formatter, "invalid project: {error}"),
1373 }
1374 }
1375}
1376
1377impl std::error::Error for ProjectLoadError {
1378 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1379 match self {
1380 Self::TooLarge { .. } => None,
1381 Self::Json(error) => Some(error),
1382 Self::InvalidProject(error) => Some(error),
1383 }
1384 }
1385}
1386
1387#[derive(Debug)]
1389#[non_exhaustive]
1390pub enum ProjectWriteError {
1391 TooLarge {
1393 maximum: usize,
1395 },
1396 Json(serde_json::Error),
1398}
1399
1400impl fmt::Display for ProjectWriteError {
1401 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1402 match self {
1403 Self::TooLarge { maximum } => write!(
1404 formatter,
1405 "the project JSON would be longer than {maximum} bytes, the maximum a project loads with"
1406 ),
1407 Self::Json(error) => write!(formatter, "the project does not serialize: {error}"),
1408 }
1409 }
1410}
1411
1412impl std::error::Error for ProjectWriteError {
1413 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1414 match self {
1415 Self::TooLarge { .. } => None,
1416 Self::Json(error) => Some(error),
1417 }
1418 }
1419}