Closed ahmad-cit22 closed 5 days ago
Can we extract this function into a static function that we then put a lot of tests around?
Can we extract this function into a static function that we then put a lot of tests around?
Thanks a lot.
Based on your suggestion, I moved the getRequestPortFromLine
logic into a new static method in the LogParser
utility class which ensures better testability and separation of concerns. There, I introduced a more specific InvalidArgumentException
when the port cannot be parsed.
And then wrote unit tests for the function considering various types of log lines as well as possible edge cases for invalid lines.
Hope this will solve the issue in a better approach.
[Updated] This PR fixes an issue (#53534) in the
getRequestPortFromLine
method inServeCommand.php
where failing to extract the request port from the log line resulted in anUndefined array key 1
error when usingLOG_CHANNEL=stderr
. This error would break the server when generating a URL with missing parameters, causing Artisan commands to fail.Changes:
How This Fix Solves the Issue:
This fix resolves the issue where the server breaks because the
getRequestPortFromLine
method fails to parse log lines with a datetime prefix. By updating the regex, we ensure that both types of log lines (with and without datetime) are handled correctly. Additionally, the exception handling ensures that if parsing fails, it is immediately clear which log line caused the failure, facilitating quicker debugging for devs.This way, this PR enhances the stability of Laravel's
artisan serve
command by addressing the log parsing issue in a a manner which can ensure smoother development workflows. Thank you.