Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flag to control the concatenation of exception messages #238

Open
saken14 opened this issue Dec 11, 2024 · 0 comments
Open

Add a flag to control the concatenation of exception messages #238

saken14 opened this issue Dec 11, 2024 · 0 comments

Comments

@saken14
Copy link

saken14 commented Dec 11, 2024

It would be a good if there was a flag to control the concatenation of exception messages in case when I want to display real exception message for users insead of message + stack trace as a string. Please add the ability to remove a stack trace in exceptions.

For example I faced with this: "ORA-20029: ORA-06508: PL/SQL: could not find program unit being called

#0 /var/www/claim/app/Traits/EsbdEntry.php(306): App\Repositories\Api\EsbdRepository->set()
#1 /var/www/claim/app/Traits/EsbdEntry.php(86): App\Tasks\SetClaimTask->setEsbdMethod()
#2 /var/www/claim/app/Tasks/SetClaimTask.php(157): App\Tasks\SetClaimTask->setVictimObjectsEsbd()
#3 /var/www/claim/vendor/spatie/async/src/Task.php(15): App\Tasks\SetClaimTask->run()
#4 /var/www/claim/vendor/spatie/async/src/Runtime/ChildRuntime.php(26): Spatie\Async\Task->__invoke()
#5 {main}".
But actually I need only real message without stack trace - "ORA-20029: ORA-06508: PL/SQL: could not find program unit being called"

The code which is doing concatenation is in "vendor/spatie/async/src/Output/SerializableException.php:29" - $throwable = new $this->class($this->message."\n\n".$this->trace);

Now, I did a temporary solution for that by splitting a string by "\n\n".

$message = $exception->getMessage();
$pos = strpos($message, "\n\n");

if (!$pos) {
    throw $exception;
}
// убираем stack trace который spatie/async добавляет в Exception
$message = substr($message, 0, $pos);
$exceptionClass = get_class($exception);

throw new $exceptionClass($message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant