0

I have a video file to probe with the use of FFPROBE, I'm trying to catch the error so that instead of just throwing the error it updates the DB row first, setting it to state 2 (processed 0 = default, processed 0 = done, processed 2 = error).

I've tried this first:

$user     = Auth::user()->id;
$video    = Video::find($videoUploaded->video->id);
$playlist = $video->playlist->id;

...

try {
     //Line 39 $seconds
    $seconds = $ffprobe->format(config('cf.video_disk') . "/$user/$playlist/$video->ts_name")->get('duration');     
} catch (\Exeption $err) {
    $video->processed = 2;
    $video->name      = $err->getMessage();
    $video->url       = $err->getMessage();
    $video->update();
    event(new VideoUpdated($video));
    return $err->getMessage();
}

And also suppressing the error with @ and moving the DB update in the try:

try {
    //Line 39 $seconds
    $seconds = @$ffprobe->format(config('wondermark.video_disk') . "/$user/$playlist/$video->ts_name")->get('duration'); //Line 39
    if (FALSE === $seconds) {
        $video->processed = 2;
        $video->name      = $err->getMessage();
        $video->url       = $err->getMessage();
        $video->update();
    }
} catch (\Exeption $err) {
    event(new VideoUpdated($video));
    return $err->getMessage();
}

Both return the error on line #39 (see above comment) and the DB does not get updated :(

1 Answer 1

1

It seems there's only a mistake in spelling Exception, So i guess this will work:

try {
    $seconds = $ffprobe->format(config('cf.video_disk') . "/$user/$playlist/$video->ts_name")->get('duration');     
    // if no errors
} catch (\Exception $err) {
    // if error happens
    return $err->getMessage();
}

And it is more recommended that you catch throwables (PHP: Throwable - Manual) instead of exceptions:

try {
    $seconds = $ffprobe->format(config('cf.video_disk') . "/$user/$playlist/$video->ts_name")->get('duration');     
    // if no errors
} catch (\Throwable $throwable) {
    // if error happens
    return $throwable->getMessage();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.