summaryrefslogtreecommitdiff
path: root/internal/gtserror/multi.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-12-22 11:48:28 +0100
committerLibravatar GitHub <noreply@github.com>2022-12-22 11:48:28 +0100
commit1659f75ae6e491355e1d32f0f5e8b956ef70a797 (patch)
tree0cc7aba9d8c98ee0163488121328e9cd0c6b32c2 /internal/gtserror/multi.go
parent[bugfix] fix media create error not being checked (#1283) (diff)
downloadgotosocial-1659f75ae6e491355e1d32f0f5e8b956ef70a797.tar.xz
[feature] For video attachments, store + return fps, bitrate, duration (#1282)
* start messing about with different mp4 metadata extraction * heyyooo it works * add test cow * move useful multierror to gtserror package * error out if video doesn't seem to be a real mp4 * test parsing mkv in disguise as mp4 * tidy up error handling * remove extraneous line * update framerate formatting * use float32 for aspect * fixy mctesterson
Diffstat (limited to 'internal/gtserror/multi.go')
-rw-r--r--internal/gtserror/multi.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/gtserror/multi.go b/internal/gtserror/multi.go
new file mode 100644
index 000000000..1740d726c
--- /dev/null
+++ b/internal/gtserror/multi.go
@@ -0,0 +1,45 @@
+/*
+ GoToSocial
+ Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package gtserror
+
+import (
+ "errors"
+ "fmt"
+ "strings"
+)
+
+// MultiError allows encapsulating multiple errors under a singular instance,
+// which is useful when you only want to log on errors, not return early / bubble up.
+type MultiError []string
+
+func (e *MultiError) Append(err error) {
+ *e = append(*e, err.Error())
+}
+
+func (e *MultiError) Appendf(format string, args ...any) {
+ *e = append(*e, fmt.Sprintf(format, args...))
+}
+
+// Combine converts this multiError to a singular error instance, returning nil if empty.
+func (e MultiError) Combine() error {
+ if len(e) == 0 {
+ return nil
+ }
+ return errors.New(`"` + strings.Join(e, `","`) + `"`)
+}