Skip to content

Commit

Permalink
chore: better error handling for mxf2raw
Browse files Browse the repository at this point in the history
  • Loading branch information
connerdouglass committed Mar 10, 2024
1 parent d5c0b73 commit d68bcd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions examples/metadata-mxf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"

Expand All @@ -20,9 +21,10 @@ func main() {
defer cancel()

// Get the metadata for a file
metadata, err := metadata.GetMxfMetadata(ctx, "/Users/conner/Downloads/Stage AAF/AA01B7EAC60C.mxf")
metadata, err := metadata.GetMxfMetadata(ctx, "reference-media/SC0808GB.01/SC0808GB_AA01.D9722BAE3008A.mxf")
if err != nil {
panic(err)
fmt.Println(err.Error())
os.Exit(1)
}

// Log the metadata
Expand Down
7 changes: 5 additions & 2 deletions metadata/mxf2raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"os/exec"
"strings"

"github.com/spiretechnology/spireav"
)
Expand All @@ -29,12 +30,14 @@ func GetMxfMetadataWithOptions(ctx context.Context, filename string, opts Metada
}

// Create the output buffer to capture stdout
var stdoutBuffer bytes.Buffer
var stdoutBuffer, stderrBuffer bytes.Buffer
cmd.Stdout = &stdoutBuffer
cmd.Stderr = &stderrBuffer

// Run the command
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("running mxf2raw: %s", err)
errStr := strings.TrimSpace(stderrBuffer.String())
return nil, fmt.Errorf("running mxf2raw: %s: %s", err, errStr)
}

// Get the bytes from the output
Expand Down

0 comments on commit d68bcd3

Please sign in to comment.