Skip to content

Commit

Permalink
error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
frr committed Feb 1, 2018
1 parent 4afe452 commit 983d2f1
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions transcoder/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"
"regexp"
"strconv"
"log"
)

type Transcoder struct {
Expand Down Expand Up @@ -140,50 +139,49 @@ func (t *Transcoder) Initialize(inputPath string, outputPath string, configurati

}

func (t *Transcoder) Run() (<-chan bool) {
func (t *Transcoder) Run() (<-chan bool, error) {
done := make(chan bool)
var err error

command := t.GetCommand()

proc := exec.Command("/bin/sh", "-c", command)

t.SetProccess(proc)

go func() {
perror := proc.Start()
if perror != nil {
log.Fatal(perror)
err := proc.Start()
if err != nil {
return
}

proc.Wait()

done <- true
close(done)
}()

return done
return done, err

}

// TODO: ONLY WORKS FOR VIDEO FILES
func (t Transcoder) Output() (chan models.Progress) {
func (t Transcoder) Output() (<-chan models.Progress, error) {
out := make(chan models.Progress)
var err error

go func() {
defer close(out)

stderr, serr := t.Process().StderrPipe()
if serr != nil {
log.Fatal(serr)
stderr, stderror := t.Process().StderrPipe()
if err != nil {
err = stderror
return
}

scanner := bufio.NewScanner(stderr)

split := func(data []byte, atEOF bool) (advance int, token []byte, err error) {

if err != nil {
log.Fatal(err)
return 0, nil, nil
}
split := func(data []byte, atEOF bool) (advance int, token []byte, spliterror error) {

if atEOF && len(data) == 0 {
return 0, nil, nil
Expand Down Expand Up @@ -244,12 +242,10 @@ func (t Transcoder) Output() (chan models.Progress) {
}
}

defer close(out)

if err := scanner.Err(); err != nil {
log.Fatal(err)
if scerror := scanner.Err(); err != nil {
err = scerror
}
}()

return out
return out, err
}

0 comments on commit 983d2f1

Please sign in to comment.