Skip to content

Commit 12e258c

Browse files
committed
Improve stack trace
1 parent c8beb58 commit 12e258c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Internal/Runtime/SourceExecutor.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Phplrt\Contracts\Lexer\TokenInterface;
3030
use Phplrt\Contracts\Source\FileInterface;
3131
use Phplrt\Contracts\Source\ReadableInterface;
32+
use Phplrt\Exception\RuntimeException;
3233
use Phplrt\Lexer\Token\Composite;
3334
use Phplrt\Position\Position;
3435
use Phplrt\Source\File;
@@ -160,10 +161,16 @@ public function execute(ReadableInterface $source): \Traversable
160161
default:
161162
throw new \LogicException(\sprintf('Non implemented token "%s"', $token->getName()));
162163
}
163-
} catch (PreprocessException $e) {
164-
throw $e;
165164
} catch (RuntimeExceptionInterface $e) {
166-
throw new PreprocessException($e->getMessage(), $e->getCode(), $e);
165+
$message = $e instanceof RuntimeException
166+
? $e->getOriginalMessage()
167+
: $e->getMessage();
168+
169+
$exception = new PreprocessException($message, (int)$e->getCode(), $e);
170+
$exception->setSource($source);
171+
$exception->setToken($token);
172+
173+
throw $exception;
167174
} catch (\Throwable $e) {
168175
throw PreprocessException::fromSource($e->getMessage(), $source, $token, $e);
169176
}

0 commit comments

Comments
 (0)