peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.37k stars 203 forks source link

Runtime error not captured #1074

Open dennismarksbury opened 2 years ago

dennismarksbury commented 2 years ago

When I run the application, the code is failing, but there is no error that I can find. If I debug into the code, I am only able to go part way through the code and then the code appears to crash, without any notification.

I have pushed the test projects to the following GitHub: https://github.com/dennismarksbury/LaravelOnPeachPie

Code fails here: Web1/index.php : Line 52

Environment: Windows Visual Studio Pro 2019

Peachpie.NET.Sdk/1.0.0-appv4909 Peachpie.AspNetCore.Web/1.0.24

Question: is there a "preferred" environment?

jakubmisek commented 2 years ago

Thank you, it seems the ASP.NET Core Middleware does not propagate the error to the request pipeline (I'll try to fix that)

Anyways; there are errors and notices in the console and the debug Output pane:

PHP (Notice): Script 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' inclusion failed. Cause: Script file 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' not found. Search paths: include_path is '.', working directory is 'vendor/composer' 

Exception thrown: 'Pchp.Library.Spl.Error' in Peachpie.Runtime.dll

PHP (E_ERROR): Error: Class 'Symfony\Component\HttpKernel\HttpKernelInterface' not found in C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(29,0)
Stack trace:
#0 C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1\vendor\composer\ClassLoader.php(428,12): {main}
#1 : ClassLoader->loadClass($class)
#2 : {main}
jakubmisek commented 2 years ago

Peachpie.NET.Sdk/1.0.0-appv4909 Peachpie.AspNetCore.Web/1.0.24

both versions should be the same - otherwise you have a NuGet warning when building the project

jakubmisek commented 2 years ago

Sadly Laravel starts the response, so the developer exception page (UseDeveloperExceptionPage()) is not able to output its own content anymore.

The iis express log contains all the PHP notices and errors tho. You can also handle the exception in Visual Studio or any other IDE while debugging.

image

What we can do, is implement a "default" PHP exception handler and output the exception to the response by ourselves. But usually, it's all handled by ASP.NET already.

dennismarksbury commented 2 years ago

So can i use the following?

Peachpie.NET.Sdk/1.0.0-appv4909 Peachpie.AspNetCore.Web/1.0.0-appv4909

Dennis Marksbury

"Do the best you can until you know better. Then when you know better, do better." #MayaAngelou

On Tue, Oct 25, 2022 at 8:08 AM Jakub Míšek @.***> wrote:

Peachpie.NET.Sdk/1.0.0-appv4909 Peachpie.AspNetCore.Web/1.0.24

both versions should be the same - otherwise you have a NuGet warning when building the project

— Reply to this email directly, view it on GitHub https://github.com/peachpiecompiler/peachpie/issues/1074#issuecomment-1290441923, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOLO2CRGZVVN3WGPA7AXBDWE7ESPANCNFSM6AAAAAARESOWEY . You are receiving this because you authored the thread.Message ID: @.***>

dennismarksbury commented 2 years ago

So this is interesting... it says that the HttpKernelInterface is not found... but I don't understand why it cannot find it... it is in the project, exactly where I would expect it to be. What would prevent this interface from being found?

Dennis Marksbury

"Do the best you can until you know better. Then when you know better, do better." #MayaAngelou

On Tue, Oct 25, 2022 at 8:22 AM Jakub Míšek @.***> wrote:

Sadly Laravel starts the response, so the developer exception page ( UseDeveloperExceptionPage()) is not able to output its own content anymore.

The iis express log contains all the PHP notices and errors tho. You can also handle the exception in Visual Studio or any other IDE while debugging.

[image: image] https://user-images.githubusercontent.com/842150/197771597-c2199e3f-2177-480a-980b-2ae36d71c7bf.png

What we can do, is implement a "default" PHP exception handler and output the exception to the response by ourselves. But usually, it's all handled by ASP.NET already.

— Reply to this email directly, view it on GitHub https://github.com/peachpiecompiler/peachpie/issues/1074#issuecomment-1290458613, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOLO2CWNYHUKVYDARLQOJLWE7GIXANCNFSM6AAAAAARESOWEY . You are receiving this because you authored the thread.Message ID: @.***>

jakubmisek commented 2 years ago

So can i use the following? Peachpie.NET.Sdk/1.0.0-appv4909 Peachpie.AspNetCore.Web/1.0.0-appv4909

the latest official release is 1.1.2 or the latest nightly build [1.2.0-r14735](https://www.nuget.org/packages/Peachpie.NET.Sdk/1.2.0-r14735)

https://www.nuget.org/packages/peachpie.net.sdk

jakubmisek commented 2 years ago

So this is interesting... it says that the HttpKernelInterface is not found... but I don't understand why it cannot find it... it is in the project, exactly where I would expect it to be. What would prevent this interface from being found?

It is probably caused by the first error:

PHP (Notice): Script 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' inclusion failed. Cause: Script file 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' not found. Search paths: include_path is '.', working directory is 'vendor/composer' 

isn't this particular script file excluded from compilation?

dennismarksbury commented 2 years ago

As far as I can tell, the HttpKernelInterface.php is included for compiling...

[image: image.png]

Dennis Marksbury

"Do the best you can until you know better. Then when you know better, do better." #MayaAngelou

On Tue, Oct 25, 2022 at 9:08 AM Jakub Míšek @.***> wrote:

So this is interesting... it says that the HttpKernelInterface is not found... but I don't understand why it cannot find it... it is in the project, exactly where I would expect it to be. What would prevent this interface from being found?

It is probably caused by the first error:

PHP (Notice): Script 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' inclusion failed. Cause: Script file 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' not found. Search paths: include_path is '.', working directory is 'vendor/composer'

isn't this particular script file excluded from compilation?

— Reply to this email directly, view it on GitHub https://github.com/peachpiecompiler/peachpie/issues/1074#issuecomment-1290525057, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOLO2HVNS3WNVOGPT6GRH3WE7LTDANCNFSM6AAAAAARESOWEY . You are receiving this because you authored the thread.Message ID: @.***>

dennismarksbury commented 2 years ago

My image didn't come through.... here's the line in the .msbuildproj file

<Compile Include="vendor\symfony\Component\HttpKernel\HttpKernelInterface.php" />

So I would assume it is compiling it.

jakubmisek commented 2 years ago

I see!

Yep, this might be a really important bug.

Edit: ok not a bug :/

jakubmisek commented 2 years ago

it is looking for: vendor\symfony\http-kernel\HttpKernelInterface.php not: vendor\symfony\Component\http-kernel\HttpKernelInterface.php


this file is indeed not compiled

dennismarksbury commented 2 years ago

Question... so when the PHP classes are loaded, is it loading by namespace or by physical path based on namespace?

On Tue, Oct 25, 2022 at 9:49 AM Jakub Míšek @.***> wrote:

it is looking for: vendor\symfony\http-kernel\HttpKernelInterface.php not: vendor\symfony\Component\http-kernel\HttpKernelInterface.php

— Reply to this email directly, view it on GitHub https://github.com/peachpiecompiler/peachpie/issues/1074#issuecomment-1290593067, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOLO2APBBILKTVVU3ULWGDWE7QNPANCNFSM6AAAAAARESOWEY . You are receiving this because you authored the thread.Message ID: @.***>

jakubmisek commented 2 years ago

Question... so when the PHP classes are loaded, is it loading by namespace or by physical path based on namespace?

those are a few separate steps

When the class that is not declared is used, PHP calls a class loader (in this case composer with its set of rules, usually based on the so-called PSR-4)

Then the file containing the class declaration must be included -> composer does it by parsing the class namespace to construct the expected file path, it checks that the file exists on the file system, and then it includes it. If this fails, PHP throws a warning, but continues.

With PeachPie, the file may exist on disk, but if it's not compiled, the inclusion fails.

Finally, PHP actually uses the class (that's expected to be loaded now), which may fail with fatal error.

dennismarksbury commented 2 years ago

Ok, I will try to move those files out of the "vendor" folder and into the root to see if that helps.

Dennis Marksbury

"Do the best you can until you know better. Then when you know better, do better." #MayaAngelou

On Tue, Oct 25, 2022 at 10:26 AM Jakub Míšek @.***> wrote:

Question... so when the PHP classes are loaded, is it loading by namespace or by physical path based on namespace?

those are a few separate steps

When the class that is not declared is used, PHP calls a class loader (in this case composer with its set of rules, usually based on the so-called PSR-4)

Then the file containing the class declaration must be included -> composer does it by parsing the class namespace to construct the expected file path, it checks that the file exists on the file system, and then it includes it. If this fails, PHP throws a warning, but continues.

With PeachPie, the file may exist on disk, but if it's not compiled, the inclusion fails.

Finally, PHP actually uses the class (that's expected to be loaded now), which may fail with fatal error.

— Reply to this email directly, view it on GitHub https://github.com/peachpiecompiler/peachpie/issues/1074#issuecomment-1290644423, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOLO2AI6TIXFCSPTI6MLZ3WE7UZBANCNFSM6AAAAAARESOWEY . You are receiving this because you authored the thread.Message ID: @.***>

jakubmisek commented 2 years ago

@dennismarksbury it's not about moving the files ... they are there but explicitly excluded in your .msbuild

dennismarksbury commented 2 years ago

I deleted all folders that were explicitly excluded from the build in the \vendor\symphony folder...

Removed the following line from the .msbuildproject file

<None Remove="vendor\symfony\**" />

Ensure that the compile include IS still there:

<Compile Include="vendor\symfony\Component\HttpKernel\HttpKernelInterface.php" />

I still get the same error.

jakubmisek commented 2 years ago

As mentioned earlier, you're looking at wrong path:

vendor\symfony\http-kernel\HttpKernelInterface.php not: vendor\symfony\Component\http-kernel\HttpKernelInterface.php

That's the problem.

Also everything is in the application log, I guess there is still the following: PHP (Notice): Script 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' inclusion failed.

(not \Component\ in there)

dennismarksbury commented 2 years ago

Ok, i've figured it out! all these classes are defined in autoload_static.php, which points to incorrect directories. I am working to clean this up.

dennismarksbury commented 1 year ago

Hi Jakub

I know it's been a long while since I last worked on this... but I am trying to get back to it... I am slowly making some progress...

I have found that there are some helper functions that Laravel has defined, they seem to be "global" in nature... for example there are tap() and value() and view() functions...

I am still trying to figure out where these functions are defined, but in the meantime, is there a way to refer to them globally without altering a ton of code? Here is a bit of reference for the tap()

https://laravel-news.com/collection-tap

Any help would be much appreciated!

Dennis Marksbury

"Do the best you can until you know better. Then when you know better, do better." #MayaAngelou

On Tue, Oct 25, 2022 at 11:05 AM Jakub Míšek @.***> wrote:

As mentioned earlier, you're looking at wrong path:

vendor\symfony\http-kernel\HttpKernelInterface.php not: vendor\symfony\Component\http-kernel\HttpKernelInterface.php

That's the problem.

Also everything is in the application log, I guess there is still the following: PHP (Notice): Script 'C:\Users\jmise\Projects\LaravelOnPeachPie\Web1\Web1.Server\vendor\composer/../symfony/http-kernel/HttpKernelInterface.php' inclusion failed.

(not \Component in there)

— Reply to this email directly, view it on GitHub https://github.com/peachpiecompiler/peachpie/issues/1074#issuecomment-1290715501, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOLO2GVYEY3ZMDTAA6C5OTWE7ZMRANCNFSM6AAAAAARESOWEY . You are receiving this because you were mentioned.Message ID: @.***>

jakubmisek commented 1 year ago

Hi @dennismarksbury ,

Thanks for the details. Laravel does a lot of class aliasing, and global functions like tap() are usually in helpers:

vendor\laravel\framework\src\Illuminate\Support\helpers.php

Although they are defined conditionally (inside if statement), so the compiler cannot call them directly - there will be an overhead.