From d68bcd3a0866d07183f273a0d256e0174d641cb6 Mon Sep 17 00:00:00 2001 From: connerdouglass Date: Sun, 10 Mar 2024 12:53:18 -0400 Subject: [PATCH] chore: better error handling for mxf2raw --- examples/metadata-mxf/main.go | 6 ++++-- metadata/mxf2raw.go | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/metadata-mxf/main.go b/examples/metadata-mxf/main.go index 8b3e72c..5eb2be3 100644 --- a/examples/metadata-mxf/main.go +++ b/examples/metadata-mxf/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "os" "os/signal" "syscall" @@ -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 diff --git a/metadata/mxf2raw.go b/metadata/mxf2raw.go index c7822a4..8a81599 100644 --- a/metadata/mxf2raw.go +++ b/metadata/mxf2raw.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "os/exec" + "strings" "github.com/spiretechnology/spireav" ) @@ -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