-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(commands): add Rescuer trait to MusicCommand
- Introduced the Rescuer trait to handle exceptions in MusicCommand. - Removed the private rescue method from MusicCommand to improve code organization. - Enhanced error handling by utilizing the new Rescuer trait.
- Loading branch information
Showing
2 changed files
with
52 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2024 guanguans<[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/guanguans/music-dl | ||
*/ | ||
|
||
namespace App\Concerns; | ||
|
||
use Illuminate\Contracts\Debug\ExceptionHandler; | ||
|
||
/** | ||
* @mixin \Illuminate\Console\Command | ||
*/ | ||
trait Rescuer | ||
{ | ||
/** | ||
* @template TValue | ||
* | ||
* @noinspection RedundantDocCommentTagInspection | ||
* | ||
* @psalm-suppress InvalidReturnType | ||
* @psalm-suppress InvalidReturnStatement | ||
* | ||
* @param callable(): TValue $callback | ||
* @param bool|callable(\Throwable): bool $report | ||
* | ||
* @throws \Illuminate\Contracts\Container\BindingResolutionException | ||
* | ||
* @return \Throwable|TValue | ||
*/ | ||
public function rescue(callable $callback, bool|callable $report = false): mixed | ||
{ | ||
return rescue( | ||
$callback, | ||
function (\Throwable $throwable): \Throwable { | ||
$this->laravel->make(ExceptionHandler::class)->renderForConsole($this->output, $throwable); | ||
|
||
return $throwable; | ||
}, | ||
$report | ||
); | ||
} | ||
} |