Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 8987278

Browse files
authored
Improved error handling (#57)
1 parent d52e386 commit 8987278

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

cmd/common.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ func transcribeWithBatchAPI(ctx context.Context, appID string, corpusPath string
402402
barClearOnError(bar)
403403
return results, err
404404
}
405+
case sluv1.Operation_STATUS_ERROR:
406+
barClearOnError(bar)
407+
return results, fmt.Errorf("%s", status.GetOperation().GetError())
405408
}
406409
}
407410
if len(pending) == 0 {
@@ -506,12 +509,18 @@ func transcribeWithStreamingAPI(ctx context.Context, appID string, corpusPath st
506509
LanguageCode: "en-US",
507510
},
508511
}})
512+
if err != nil {
513+
return nil, err
514+
}
509515

510516
audios = append(audios, aci.Audio)
511517
transcripts = append(transcripts, aci.Transcript)
512-
_ = stream.Send(&sluv1.SLURequest{StreamingRequest: &sluv1.SLURequest_Start{Start: &sluv1.SLUStart{
518+
err = stream.Send(&sluv1.SLURequest{StreamingRequest: &sluv1.SLURequest_Start{Start: &sluv1.SLUStart{
513519
AppId: appID,
514520
}}})
521+
if err != nil {
522+
return nil, err
523+
}
515524

516525
audioFilePath := path.Join(path.Dir(corpusPath), aci.Audio)
517526
if corpusPath == aci.Audio {
@@ -529,15 +538,24 @@ func transcribeWithStreamingAPI(ctx context.Context, appID string, corpusPath st
529538
return err
530539
}
531540

532-
_ = stream.Send(&sluv1.SLURequest{
541+
err = stream.Send(&sluv1.SLURequest{
533542
StreamingRequest: &sluv1.SLURequest_Audio{
534543
Audio: buf.Bytes(),
535544
},
536545
})
546+
if err != nil {
547+
return err
548+
}
537549
return nil
538550
})
539-
_ = stream.Send(&sluv1.SLURequest{StreamingRequest: &sluv1.SLURequest_Stop{Stop: &sluv1.SLUStop{}}})
540-
_ = stream.CloseSend()
551+
err = stream.Send(&sluv1.SLURequest{StreamingRequest: &sluv1.SLURequest_Stop{Stop: &sluv1.SLUStop{}}})
552+
if err != nil {
553+
return nil, err
554+
}
555+
err = stream.CloseSend()
556+
if err != nil {
557+
return nil, err
558+
}
541559
if err != nil {
542560
barClearOnError(bar)
543561
return results, err

0 commit comments

Comments
 (0)