Skip to content

Commit 34aaa64

Browse files
committed
upsome for tips error
1 parent a9ee7ae commit 34aaa64

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Component/ErrorHandler.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Inhere\Console\AbstractApplication;
1212
use Inhere\Console\Contract\ErrorHandlerInterface;
13+
use Inhere\Console\Exception\PromptException;
1314
use Throwable;
1415
use Toolkit\Cli\Highlighter;
1516
use function file_get_contents;
@@ -29,20 +30,26 @@ class ErrorHandler implements ErrorHandlerInterface
2930
*/
3031
public function handle(Throwable $e, AbstractApplication $app): void
3132
{
33+
if ($e instanceof PromptException) {
34+
$app->getOutput()->error($e->getMessage());
35+
return;
36+
}
37+
3238
$class = get_class($e);
3339

3440
// open debug, throw exception
3541
if ($app->isDebug()) {
36-
$tpl = <<<ERR
42+
$tpl = <<<ERR
3743
\n<error> Error </error> <mga>%s</mga>
3844
3945
At File <cyan>%s</cyan> line <bold>%d</bold>
4046
Exception class is <magenta>$class</magenta>
4147
<comment>Code View:</comment>\n\n%s
4248
<comment>Code Trace:</comment>\n\n%s\n
4349
ERR;
44-
$line = $e->getLine();
45-
$file = $e->getFile();
50+
$line = $e->getLine();
51+
$file = $e->getFile();
52+
4653
$snippet = Highlighter::create()->highlightSnippet(file_get_contents($file), $line, 3, 3);
4754
$message = sprintf(
4855
$tpl, // $e->getCode(),
@@ -58,10 +65,11 @@ public function handle(Throwable $e, AbstractApplication $app): void
5865
}
5966

6067
$app->write($message, false);
61-
} else {
62-
// simple output
63-
$app->getOutput()->error('An error occurred! MESSAGE: ' . $e->getMessage());
64-
$app->write("\nYou can use '--debug 4' to see error details.");
68+
return;
6569
}
70+
71+
// simple output
72+
$app->getOutput()->error('An error occurred! MESSAGE: ' . $e->getMessage());
73+
$app->write("\nYou can use '--debug 4' to see error details.");
6674
}
6775
}

0 commit comments

Comments
 (0)