1use crate::{ClipId, CompositionId, DataSetId, EffectProblem, EffectResourceId, NodeId, TrackId};
2use alpha2_media::SourceId;
3use std::fmt;
4
5#[derive(Clone, Debug, Eq, PartialEq)]
8pub enum ShapeOwner {
9 Source(SourceId),
11 Clip(ClipId),
13 Node {
15 composition: CompositionId,
17 node: NodeId,
19 },
20}
21
22impl fmt::Display for ShapeOwner {
23 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 Self::Source(source) => write!(formatter, "source {source}"),
26 Self::Clip(clip) => write!(formatter, "clip {clip}"),
27 Self::Node { composition, node } => {
28 write!(formatter, "composition {composition} node {node}")
29 }
30 }
31 }
32}
33
34#[derive(Clone, Debug, Eq, PartialEq)]
36pub enum DataOwner {
37 Clip(ClipId),
39 Track(TrackId),
41 Master,
43 Transition {
45 track: TrackId,
47 from: ClipId,
49 to: ClipId,
51 },
52 Node {
54 composition: CompositionId,
56 node: NodeId,
58 },
59 Source(SourceId),
61}
62
63impl fmt::Display for DataOwner {
64 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
65 match self {
66 Self::Clip(clip) => write!(formatter, "clip {clip}"),
67 Self::Track(track) => write!(formatter, "track {track}"),
68 Self::Master => formatter.write_str("the master bus"),
69 Self::Transition { track, from, to } => {
70 write!(formatter, "track {track} transition {from} to {to}")
71 }
72 Self::Node { composition, node } => {
73 write!(formatter, "composition {composition} node {node}")
74 }
75 Self::Source(source) => write!(formatter, "source {source}"),
76 }
77 }
78}
79
80#[derive(Clone, Debug, Eq, PartialEq)]
82pub enum EffectOwner {
83 Node {
85 composition: CompositionId,
87 node: NodeId,
89 },
90 Transition {
92 track: TrackId,
94 from: ClipId,
96 to: ClipId,
98 },
99}
100
101impl fmt::Display for EffectOwner {
102 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
103 match self {
104 Self::Node { composition, node } => {
105 write!(formatter, "composition {composition} node {node}")
106 }
107 Self::Transition { track, from, to } => {
108 write!(
109 formatter,
110 "the transition from {from} to {to} on track {track}"
111 )
112 }
113 }
114 }
115}
116
117impl fmt::Display for EffectProblem {
118 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
119 match self {
120 Self::UnknownBuiltin => formatter.write_str("is not a built-in"),
121 Self::Version { expected } => write!(formatter, "needs version {expected}"),
122 Self::Kind => formatter.write_str("is used as the wrong kind"),
123 Self::UnknownParam(name) => write!(formatter, "has no parameter {name}"),
124 Self::InvalidParam(name) => {
125 write!(
126 formatter,
127 "has a parameter {name} of the wrong type or out of range"
128 )
129 }
130 Self::Inputs => formatter.write_str("does not get exactly its declared inputs"),
131 Self::Resources => formatter.write_str("does not get exactly its declared resources"),
132 }
133 }
134}
135
136#[derive(Clone, Debug, Eq, PartialEq)]
138#[non_exhaustive]
139pub enum ModelError {
140 UnsupportedSchemaVersion {
142 found: u32,
144 },
145 TooManyDataSets {
147 found: usize,
149 maximum: usize,
151 },
152 DuplicateDataSetId(DataSetId),
154 InvalidDataSet {
156 data: DataSetId,
158 problem: crate::DataProblem,
160 },
161 InvalidDataBinding {
163 owner: DataOwner,
165 at: String,
168 problem: crate::BindingProblem,
170 },
171 EmptyIdentifier,
173 DuplicateSourceId(SourceId),
175 DuplicateEffectResourceId(EffectResourceId),
177 DuplicateTrackId(TrackId),
179 DuplicateClipId(ClipId),
181 EmptyLocator {
183 source: SourceId,
185 },
186 AudioOnImage {
188 source: SourceId,
190 },
191 InvalidProvider {
194 source: SourceId,
196 },
197 InvalidFingerprint {
199 source: SourceId,
201 },
202 ContradictoryColor {
205 source: SourceId,
207 },
208 InvalidGenerator {
211 source: SourceId,
213 },
214 InvalidShape {
217 owner: ShapeOwner,
219 at: String,
221 problem: crate::ShapeProblem,
223 },
224 InvalidLayout {
227 owner: ShapeOwner,
229 at: String,
231 problem: crate::LayoutProblem,
233 },
234 EmptyEffectResourceLocator {
236 resource: EffectResourceId,
238 },
239 UnknownEffectResource {
241 clip: ClipId,
243 resource: EffectResourceId,
245 },
246 EmptyClipRange {
248 clip: ClipId,
250 },
251 NegativeClipRange {
253 clip: ClipId,
255 },
256 OverlappingClips {
258 track: TrackId,
260 first: ClipId,
262 second: ClipId,
264 },
265 UnknownClipSource {
267 clip: ClipId,
269 source: SourceId,
271 },
272 IncompatibleClipSource {
274 clip: ClipId,
276 track: TrackId,
278 source: SourceId,
280 },
281 InvalidVisualProperties {
283 clip: ClipId,
285 },
286 InvalidAudioProperties {
288 clip: ClipId,
290 },
291 InvalidTrackAudio {
293 track: TrackId,
295 },
296 InvalidMasterAudio,
298 InvalidDuckingSidechain {
300 track: TrackId,
302 sidechain: TrackId,
304 },
305 UnknownComposition {
307 clip: ClipId,
309 composition: CompositionId,
311 },
312 InvalidClipComposition {
315 clip: ClipId,
317 },
318 DuplicateCompositionId(CompositionId),
320 InvalidNodeId {
323 composition: CompositionId,
325 node: NodeId,
327 },
328 DuplicateNodeId {
330 composition: CompositionId,
332 node: NodeId,
334 },
335 TooManyCompositionNodes {
337 composition: CompositionId,
339 found: usize,
341 maximum: usize,
343 },
344 InvalidNode {
348 composition: CompositionId,
350 node: NodeId,
352 },
353 UnknownNodeInput {
355 composition: CompositionId,
357 node: NodeId,
359 input: String,
361 target: NodeId,
363 },
364 CompositionCycle {
366 composition: CompositionId,
368 node: NodeId,
370 },
371 UnknownCompositionOutput {
373 composition: CompositionId,
375 node: NodeId,
377 },
378 InvalidNodeSource {
380 composition: CompositionId,
382 node: NodeId,
384 source: SourceId,
386 },
387 InvalidCompositionPorts {
390 composition: CompositionId,
392 },
393 UnknownGroupComposition {
395 composition: CompositionId,
397 node: NodeId,
399 target: CompositionId,
401 },
402 CompositionUsesItself {
404 composition: CompositionId,
406 },
407 CompositionNestedTooDeep {
410 composition: CompositionId,
412 maximum: usize,
414 },
415 TooManyInlinedNodes {
418 maximum: usize,
420 },
421 FrameDrawsTooManyNodes {
424 clip: ClipId,
426 found: u64,
428 maximum: usize,
430 },
431 InvalidCompositionSource {
434 source: SourceId,
436 },
437 InvalidEffect {
440 owner: Box<EffectOwner>,
442 id: String,
444 problem: EffectProblem,
446 },
447 UnknownNodeResource {
449 composition: CompositionId,
451 node: NodeId,
453 resource: EffectResourceId,
455 },
456 InvalidClipMask {
459 clip: ClipId,
461 },
462 InvalidCaptions {
465 track: TrackId,
467 },
468 UnknownCaptionStyle {
470 track: TrackId,
472 cue: usize,
474 name: String,
476 },
477 InvalidCaptionCueStyle {
479 track: TrackId,
481 cue: usize,
483 },
484 InvalidTimeMap {
486 clip: ClipId,
488 },
489 TooManyLoopPasses {
491 clip: ClipId,
493 found: u64,
495 maximum: u64,
497 },
498 InvalidMatte {
501 clip: ClipId,
503 },
504 InvalidClipTransition {
506 track: TrackId,
508 },
509 TransitionCycle {
512 track: TrackId,
514 at: alpha2_time::MediaTime,
516 },
517 DuplicateTransition {
519 track: TrackId,
521 first: ClipId,
523 second: ClipId,
525 },
526 TooManyDerivedCues {
529 track: TrackId,
531 },
532 UnwritableTime {
534 ticks: i64,
536 },
537 TooManyEffectResources {
539 found: usize,
541 maximum: usize,
543 },
544 TooManyCompositions {
546 found: usize,
548 maximum: usize,
550 },
551 TooManySources {
553 found: usize,
555 maximum: usize,
557 },
558 TooManyTracks {
560 found: usize,
562 maximum: usize,
564 },
565 TooManyClips {
567 found: usize,
569 maximum: usize,
571 },
572 TooManyAudioEffects {
575 found: usize,
577 maximum: usize,
579 at_ticks: i64,
581 },
582 TooMuchAudioDelay {
585 found_ms: u64,
587 maximum_ms: u32,
589 at_ticks: i64,
591 },
592 TooManyClipsOnTrack {
594 track: TrackId,
596 found: usize,
598 maximum: usize,
600 },
601 TooManyCaptionCues {
603 track: TrackId,
605 found: usize,
607 maximum: usize,
609 },
610 TooManyTransitions {
612 track: TrackId,
614 found: usize,
616 maximum: usize,
618 },
619 ZeroCanvasDimension,
621 CanvasDimensionTooLarge {
623 width: u32,
625 height: u32,
627 maximum: u32,
629 },
630 CanvasPixelBudgetExceeded {
632 pixels: u64,
634 maximum: u64,
636 },
637 InvalidBackground,
639 InvalidColorPipeline,
641 UnsupportedSampleRate {
643 found: u32,
645 minimum: u32,
647 maximum: u32,
649 },
650}
651
652#[derive(Clone, Copy, Debug, Eq, PartialEq)]
654#[non_exhaustive]
655pub enum ErrorSubject<'a> {
656 Clip(&'a ClipId),
658 Source(&'a SourceId),
660 Track(&'a TrackId),
662 Composition(&'a CompositionId),
664 DataSet(&'a DataSetId),
666 EffectResource(&'a EffectResourceId),
668}
669
670impl ModelError {
671 #[must_use]
675 pub const fn subject(&self) -> Option<ErrorSubject<'_>> {
676 use ErrorSubject::{Clip, Composition, DataSet, EffectResource, Source, Track};
677 Some(match self {
678 Self::UnsupportedSchemaVersion { .. }
679 | Self::TooManyDataSets { .. }
680 | Self::EmptyIdentifier
681 | Self::InvalidMasterAudio
682 | Self::TooManyInlinedNodes { .. }
683 | Self::TooManyCompositions { .. }
684 | Self::TooManyEffectResources { .. }
685 | Self::UnwritableTime { .. }
686 | Self::TooManySources { .. }
687 | Self::TooManyTracks { .. }
688 | Self::TooManyClips { .. }
689 | Self::TooManyAudioEffects { .. }
690 | Self::TooMuchAudioDelay { .. }
691 | Self::ZeroCanvasDimension
692 | Self::CanvasDimensionTooLarge { .. }
693 | Self::CanvasPixelBudgetExceeded { .. }
694 | Self::InvalidBackground
695 | Self::InvalidColorPipeline
696 | Self::UnsupportedSampleRate { .. } => return None,
697 Self::DuplicateDataSetId(data) | Self::InvalidDataSet { data, .. } => DataSet(data),
698 Self::InvalidDataBinding { owner, .. } => match owner {
699 DataOwner::Clip(clip) | DataOwner::Transition { from: clip, .. } => Clip(clip),
700 DataOwner::Track(track) => Track(track),
701 DataOwner::Master => return None,
702 DataOwner::Node { composition, .. } => Composition(composition),
703 DataOwner::Source(source) => Source(source),
704 },
705 Self::InvalidShape { owner, .. } | Self::InvalidLayout { owner, .. } => match owner {
706 ShapeOwner::Source(source) => Source(source),
707 ShapeOwner::Clip(clip) => Clip(clip),
708 ShapeOwner::Node { composition, .. } => Composition(composition),
709 },
710 Self::InvalidEffect { owner, .. } => match &**owner {
711 EffectOwner::Node { composition, .. } => Composition(composition),
712 EffectOwner::Transition { from, .. } => Clip(from),
713 },
714 Self::DuplicateSourceId(source)
715 | Self::EmptyLocator { source }
716 | Self::AudioOnImage { source }
717 | Self::InvalidProvider { source }
718 | Self::InvalidFingerprint { source }
719 | Self::ContradictoryColor { source }
720 | Self::InvalidGenerator { source }
721 | Self::InvalidCompositionSource { source } => Source(source),
722 Self::DuplicateEffectResourceId(resource)
723 | Self::EmptyEffectResourceLocator { resource } => EffectResource(resource),
724 Self::DuplicateTrackId(track)
725 | Self::InvalidTrackAudio { track }
726 | Self::InvalidDuckingSidechain { track, .. }
727 | Self::InvalidCaptions { track }
728 | Self::UnknownCaptionStyle { track, .. }
729 | Self::InvalidCaptionCueStyle { track, .. }
730 | Self::InvalidClipTransition { track }
731 | Self::TransitionCycle { track, .. }
732 | Self::DuplicateTransition { track, .. }
733 | Self::TooManyClipsOnTrack { track, .. }
734 | Self::TooManyCaptionCues { track, .. }
735 | Self::TooManyDerivedCues { track }
736 | Self::TooManyTransitions { track, .. } => Track(track),
737 Self::DuplicateClipId(clip)
738 | Self::UnknownEffectResource { clip, .. }
739 | Self::EmptyClipRange { clip }
740 | Self::NegativeClipRange { clip }
741 | Self::OverlappingClips { second: clip, .. }
742 | Self::UnknownClipSource { clip, .. }
743 | Self::IncompatibleClipSource { clip, .. }
744 | Self::InvalidVisualProperties { clip }
745 | Self::InvalidAudioProperties { clip }
746 | Self::UnknownComposition { clip, .. }
747 | Self::InvalidClipComposition { clip }
748 | Self::FrameDrawsTooManyNodes { clip, .. }
749 | Self::InvalidClipMask { clip }
750 | Self::InvalidTimeMap { clip }
751 | Self::TooManyLoopPasses { clip, .. }
752 | Self::InvalidMatte { clip } => Clip(clip),
753 Self::DuplicateCompositionId(composition)
754 | Self::InvalidNodeId { composition, .. }
755 | Self::DuplicateNodeId { composition, .. }
756 | Self::TooManyCompositionNodes { composition, .. }
757 | Self::InvalidNode { composition, .. }
758 | Self::UnknownNodeInput { composition, .. }
759 | Self::CompositionCycle { composition, .. }
760 | Self::UnknownCompositionOutput { composition, .. }
761 | Self::InvalidNodeSource { composition, .. }
762 | Self::InvalidCompositionPorts { composition }
763 | Self::UnknownGroupComposition { composition, .. }
764 | Self::CompositionUsesItself { composition }
765 | Self::CompositionNestedTooDeep { composition, .. }
766 | Self::UnknownNodeResource { composition, .. } => Composition(composition),
767 })
768 }
769}
770
771impl fmt::Display for ModelError {
772 #[allow(clippy::too_many_lines)]
773 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
774 match self {
775 Self::UnsupportedSchemaVersion { found } => {
776 write!(formatter, "unsupported schema version {found}")
777 }
778 Self::EmptyIdentifier => formatter.write_str("document contains an empty identifier"),
779 Self::DuplicateSourceId(id) => write!(formatter, "duplicate source ID {id}"),
780 Self::DuplicateEffectResourceId(id) => {
781 write!(formatter, "duplicate effect resource ID {id}")
782 }
783 Self::DuplicateTrackId(id) => write!(formatter, "duplicate track ID {id}"),
784 Self::DuplicateClipId(id) => write!(formatter, "duplicate clip ID {id}"),
785 Self::EmptyLocator { source } => {
786 write!(formatter, "source {source} has an empty locator")
787 }
788 Self::AudioOnImage { source } => {
789 write!(
790 formatter,
791 "source {source} is a still image and has no audio"
792 )
793 }
794 Self::InvalidGenerator { source } => {
795 write!(formatter, "source {source} has an invalid generator")
796 }
797 Self::InvalidShape { owner, at, problem } => {
798 write!(formatter, "{owner} has an invalid shape: {at} {problem}")
799 }
800 Self::InvalidLayout { owner, at, problem } => {
801 write!(formatter, "{owner} has an invalid layout: {at} {problem}")
802 }
803 Self::ContradictoryColor { source } => write!(
804 formatter,
805 "source {source} declares a dynamic range its transfer contradicts"
806 ),
807 Self::InvalidFingerprint { source } => {
808 write!(formatter, "source {source} has an invalid fingerprint")
809 }
810 Self::InvalidProvider { source } => {
811 write!(formatter, "source {source} has an invalid provider")
812 }
813 Self::EmptyEffectResourceLocator { resource } => {
814 write!(formatter, "effect resource {resource} has an empty locator")
815 }
816 Self::UnknownEffectResource { clip, resource } => {
817 write!(
818 formatter,
819 "clip {clip} references unknown effect resource {resource}"
820 )
821 }
822 Self::EmptyClipRange { clip } => write!(formatter, "clip {clip} has an empty range"),
823 Self::NegativeClipRange { clip } => {
824 write!(formatter, "clip {clip} has a range before timeline origin")
825 }
826 Self::OverlappingClips {
827 track,
828 first,
829 second,
830 } => write!(
831 formatter,
832 "clips {first} and {second} overlap without a covering transition on track {track}"
833 ),
834 Self::UnknownClipSource { clip, source } => {
835 write!(formatter, "clip {clip} references unknown source {source}")
836 }
837 Self::IncompatibleClipSource {
838 clip,
839 track,
840 source,
841 } => {
842 write!(
843 formatter,
844 "clip {clip} cannot use source {source} on track {track}"
845 )
846 }
847 Self::InvalidVisualProperties { clip } => {
848 write!(formatter, "clip {clip} has invalid visual properties")
849 }
850 Self::InvalidAudioProperties { clip } => {
851 write!(formatter, "clip {clip} has invalid audio properties")
852 }
853 Self::InvalidTrackAudio { track } => {
854 write!(formatter, "track {track} has invalid audio bus settings")
855 }
856 Self::InvalidMasterAudio => {
857 write!(formatter, "the project master bus is invalid")
858 }
859 Self::InvalidDuckingSidechain { track, sidechain } => write!(
860 formatter,
861 "track {track} cannot duck from sidechain track {sidechain}"
862 ),
863 Self::UnknownComposition { clip, composition } => {
864 write!(
865 formatter,
866 "clip {clip} references unknown composition {composition}"
867 )
868 }
869 Self::InvalidClipComposition { clip } => {
870 write!(
871 formatter,
872 "clip {clip} has an invalid composition reference"
873 )
874 }
875 Self::DuplicateCompositionId(id) => write!(formatter, "duplicate composition ID {id}"),
876 Self::InvalidNodeId { composition, node } => {
877 write!(
878 formatter,
879 "composition {composition} has node ID {node}, which has a `/`"
880 )
881 }
882 Self::DuplicateNodeId { composition, node } => {
883 write!(
884 formatter,
885 "composition {composition} has duplicate node ID {node}"
886 )
887 }
888 Self::TooManyCompositionNodes {
889 composition,
890 found,
891 maximum,
892 } => write!(
893 formatter,
894 "composition {composition} has {found} nodes; the maximum is {maximum}"
895 ),
896 Self::InvalidNode { composition, node } => {
897 write!(
898 formatter,
899 "node {node} of composition {composition} has an invalid setting"
900 )
901 }
902 Self::UnknownNodeInput {
903 composition,
904 node,
905 input,
906 target,
907 } => write!(
908 formatter,
909 "input {input} of node {node} in composition {composition} names unknown node {target}"
910 ),
911 Self::CompositionCycle { composition, node } => write!(
912 formatter,
913 "node {node} of composition {composition} depends on its own output"
914 ),
915 Self::UnknownCompositionOutput { composition, node } => write!(
916 formatter,
917 "composition {composition} outputs unknown node {node}"
918 ),
919 Self::InvalidNodeSource {
920 composition,
921 node,
922 source,
923 } => write!(
924 formatter,
925 "node {node} of composition {composition} cannot show source {source}"
926 ),
927 Self::InvalidCompositionPorts { composition } => write!(
928 formatter,
929 "composition {composition} has invalid group inputs or controls"
930 ),
931 Self::UnknownGroupComposition {
932 composition,
933 node,
934 target,
935 } => write!(
936 formatter,
937 "group node {node} of composition {composition} names unknown composition {target}"
938 ),
939 Self::CompositionUsesItself { composition } => {
940 write!(formatter, "composition {composition} uses itself")
941 }
942 Self::CompositionNestedTooDeep {
943 composition,
944 maximum,
945 } => write!(
946 formatter,
947 "composition {composition} nests compositions more than {maximum} deep"
948 ),
949 Self::TooManyInlinedNodes { maximum } => write!(
950 formatter,
951 "compositions draw more than {maximum} nodes, counting each group and composition source as the nodes it draws"
952 ),
953 Self::FrameDrawsTooManyNodes {
954 clip,
955 found,
956 maximum,
957 } => write!(
958 formatter,
959 "the clips on the timeline where clip {clip} starts draw {found} composition nodes; a frame draws at most {maximum}"
960 ),
961 Self::InvalidCompositionSource { source } => {
962 write!(
963 formatter,
964 "source {source} is not a valid composition source"
965 )
966 }
967 Self::InvalidEffect { owner, id, problem } => {
968 write!(formatter, "effect {id} in {owner} {problem}")
969 }
970 Self::UnknownNodeResource {
971 composition,
972 node,
973 resource,
974 } => write!(
975 formatter,
976 "node {node} of composition {composition} references unknown effect resource {resource}"
977 ),
978 Self::InvalidClipMask { clip } => write!(formatter, "clip {clip} has an invalid mask"),
979 Self::InvalidMatte { clip } => write!(formatter, "clip {clip} has an invalid matte"),
980 Self::InvalidCaptions { track } => {
981 write!(formatter, "track {track} has invalid captions")
982 }
983 Self::UnknownCaptionStyle { track, cue, name } => write!(
984 formatter,
985 "cue {cue} of track {track} names style {name:?}, which the track does not have"
986 ),
987 Self::InvalidCaptionCueStyle { track, cue } => write!(
988 formatter,
989 "cue {cue} of track {track} has a style out of range once its patch is applied"
990 ),
991 Self::InvalidTimeMap { clip } => {
992 write!(formatter, "clip {clip} freezes outside its source range")
993 }
994 Self::TooManyLoopPasses {
995 clip,
996 found,
997 maximum,
998 } => write!(
999 formatter,
1000 "clip {clip} loops {found} times; the maximum is {maximum}"
1001 ),
1002 Self::InvalidClipTransition { track } => {
1003 write!(formatter, "track {track} has an invalid clip transition")
1004 }
1005 Self::TransitionCycle { track, at } => write!(
1006 formatter,
1007 "transitions on track {track} active at {} ticks lead from clip to clip in a circle",
1008 at.ticks()
1009 ),
1010 Self::DuplicateTransition {
1011 track,
1012 first,
1013 second,
1014 } => write!(
1015 formatter,
1016 "clips {first} and {second} have more than one transition on track {track}"
1017 ),
1018 Self::TooManyDerivedCues { track } => write!(
1019 formatter,
1020 "track {track} derives more than {} caption cues or maps more than {} words",
1021 crate::MAX_DERIVED_CUES,
1022 crate::MAX_DATA_WORDS
1023 ),
1024 Self::UnwritableTime { ticks } => write!(
1025 formatter,
1026 "a time of {ticks} ticks is beyond {} either way",
1027 alpha2_time::MAX_SERIALIZED_TICKS
1028 ),
1029 Self::TooManyEffectResources { found, maximum } => write!(
1030 formatter,
1031 "project has {found} effect resources; the maximum is {maximum}"
1032 ),
1033 Self::TooManyCompositions { found, maximum } => write!(
1034 formatter,
1035 "project has {found} compositions; the maximum is {maximum}"
1036 ),
1037 Self::TooManySources { found, maximum } => {
1038 write!(
1039 formatter,
1040 "project has {found} sources; the maximum is {maximum}"
1041 )
1042 }
1043 Self::TooManyTracks { found, maximum } => {
1044 write!(
1045 formatter,
1046 "project has {found} tracks; the maximum is {maximum}"
1047 )
1048 }
1049 Self::TooManyClips { found, maximum } => {
1050 write!(
1051 formatter,
1052 "project has {found} clips; the maximum is {maximum}"
1053 )
1054 }
1055 Self::TooManyAudioEffects {
1056 found,
1057 maximum,
1058 at_ticks,
1059 } => write!(
1060 formatter,
1061 "project has {found} audio effects holding state at tick {at_ticks}; the maximum at once is {maximum}"
1062 ),
1063 Self::TooMuchAudioDelay {
1064 found_ms,
1065 maximum_ms,
1066 at_ticks,
1067 } => write!(
1068 formatter,
1069 "project audio effects hold {found_ms} ms of delay at tick {at_ticks}; the maximum at once is {maximum_ms} ms"
1070 ),
1071 Self::TooManyClipsOnTrack {
1072 track,
1073 found,
1074 maximum,
1075 } => write!(
1076 formatter,
1077 "track {track} has {found} clips; the maximum is {maximum}"
1078 ),
1079 Self::TooManyCaptionCues {
1080 track,
1081 found,
1082 maximum,
1083 } => write!(
1084 formatter,
1085 "track {track} has {found} caption cues; the maximum is {maximum}"
1086 ),
1087 Self::TooManyTransitions {
1088 track,
1089 found,
1090 maximum,
1091 } => write!(
1092 formatter,
1093 "track {track} has {found} transitions; the maximum is {maximum}"
1094 ),
1095 Self::ZeroCanvasDimension => formatter.write_str("canvas dimensions must be positive"),
1096 Self::CanvasDimensionTooLarge {
1097 width,
1098 height,
1099 maximum,
1100 } => write!(
1101 formatter,
1102 "canvas {width}x{height} exceeds the maximum edge {maximum}"
1103 ),
1104 Self::CanvasPixelBudgetExceeded { pixels, maximum } => write!(
1105 formatter,
1106 "canvas has {pixels} pixels; the maximum is {maximum}"
1107 ),
1108 Self::InvalidBackground => {
1109 formatter.write_str("background color components must be finite and within 0..=1")
1110 }
1111 Self::InvalidColorPipeline => {
1112 formatter.write_str("the HDR peak must be within 100..=10000 nits")
1113 }
1114 Self::TooManyDataSets { found, maximum } => write!(
1115 formatter,
1116 "project has {found} data sets; the maximum is {maximum}"
1117 ),
1118 Self::DuplicateDataSetId(data) => write!(formatter, "duplicate data set id {data}"),
1119 Self::InvalidDataSet { data, problem } => {
1120 write!(formatter, "data set {data} {problem}")
1121 }
1122 Self::InvalidDataBinding { owner, at, problem } => {
1123 write!(formatter, "{owner} {at} {problem}")
1124 }
1125 Self::UnsupportedSampleRate {
1126 found,
1127 minimum,
1128 maximum,
1129 } => write!(
1130 formatter,
1131 "sample rate {found} is outside {minimum}..={maximum}"
1132 ),
1133 }
1134 }
1135}
1136
1137impl std::error::Error for ModelError {}
1138
1139#[derive(Debug)]
1141#[non_exhaustive]
1142pub enum ProjectLoadError {
1143 TooLarge {
1145 bytes: usize,
1147 maximum: usize,
1149 },
1150 Json(serde_json::Error),
1152 InvalidProject(ModelError),
1154}
1155
1156impl fmt::Display for ProjectLoadError {
1157 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1158 match self {
1159 Self::TooLarge { bytes, maximum } => {
1160 write!(
1161 formatter,
1162 "project JSON is {bytes} bytes; the maximum is {maximum}"
1163 )
1164 }
1165 Self::Json(error) => write!(formatter, "invalid project JSON: {error}"),
1166 Self::InvalidProject(error) => write!(formatter, "invalid project: {error}"),
1167 }
1168 }
1169}
1170
1171impl std::error::Error for ProjectLoadError {
1172 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1173 match self {
1174 Self::TooLarge { .. } => None,
1175 Self::Json(error) => Some(error),
1176 Self::InvalidProject(error) => Some(error),
1177 }
1178 }
1179}
1180
1181#[derive(Debug)]
1183#[non_exhaustive]
1184pub enum ProjectWriteError {
1185 TooLarge {
1187 maximum: usize,
1189 },
1190 Json(serde_json::Error),
1192}
1193
1194impl fmt::Display for ProjectWriteError {
1195 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
1196 match self {
1197 Self::TooLarge { maximum } => write!(
1198 formatter,
1199 "the project JSON would be longer than {maximum} bytes, the maximum a project loads with"
1200 ),
1201 Self::Json(error) => write!(formatter, "the project does not serialize: {error}"),
1202 }
1203 }
1204}
1205
1206impl std::error::Error for ProjectWriteError {
1207 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
1208 match self {
1209 Self::TooLarge { .. } => None,
1210 Self::Json(error) => Some(error),
1211 }
1212 }
1213}