-
Notifications
You must be signed in to change notification settings - Fork 650
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
trigger_error
makes Psalm assume the code exits
#6110
Comments
I found these snippets: https://psalm.dev/r/38c501845b<?php
class A {
public function __construct()
{
global $fooBarCondition, $cookieTheme;
$configThemeExists = true;
if ($fooBarCondition) {
trigger_error(
'Default theme %s not found!',
E_USER_ERROR
);
$configThemeExists = false;
}
if ($cookieTheme) {
return;
}
if ($configThemeExists) {
}
}
}
|
Note: we custom handle calls for trigger_error |
|
I like the second option. trigger_error has a default behaviour that is valid for a lot of project that don't touch set_error_handler and when the error_handler use the same behaviour as the default one. I think this could be handled with a return type provider accessing config, right? |
Sounds good.
This sounds sensible, but so is assuming Let's explore the problem space: There are four possible values for People may also have different error handlers for some code parts, and the only sensible option I see that would allow to configure that is to make it per-file / dir.
So I would propose something like this: <triggerError returnType="never"> <!-- project default -->
<!-- override for a certain files / folder -->
<signature returnType="($error_level is E_USER_DEPRECATED ? never : true)">
<directory name="src/Modules/FunnyModule"/>
<file name="src/strange.script.php"/>
</signature>
<signature returnType="default"> <!-- php default -->
<directory name="vendor"/>
</signature>
<signature returnType="true"> <!-- those have errors suppressed and trigger_error() always returns -->
<file name="src/Cache.php"/>
<!-- this could also be extended to support something like <referencedMethod> -->
</signature>
</errorHandler> |
That's well thought of, but I feel like it's too complex of a solution for the problem it tries to solve. If we try to be real here, out of all the projects that will ever use Psalm and out of the projects that have a error handler that will be none on 'default', 'none' or 'always', a few will ever look for the documentation to configurate it just right instead of just suppressing errors I'll try to propose the basic implementation soon, we can always build on it next if we want to be more thorough |
I am not sure a config option is best, could you analyse the implementations of set_error_handler ? |
That would basically force us to consider all those tricky points I raised above. The problem with Global state is hard to analyze 🤷 |
This should be basically fixed by the introduction of the config in #6142 unless the beahvior of trigger_error is complex |
https://psalm.dev/r/38c501845b
Ref: #6109
Originally posted by @orklah in #6109 (comment)
The text was updated successfully, but these errors were encountered: