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

Added ErrorException handler. #1

Closed
wants to merge 1 commit into from
Closed

Added ErrorException handler. #1

wants to merge 1 commit into from

Conversation

xaav
Copy link
Contributor

@xaav xaav commented Jun 9, 2011

Changed errors to exceptions, because:

  • This will probably used in a symfony environment (I'm guessing)
  • Errors are difficult to handle.

@stof
Copy link
Contributor

@stof stof commented Jun 10, 2011

@xaav As I said in your previous PR, you are only setting an error handler for the testsuite, which is totally useless as this is already done by PHPUnit when you configure it to do it (and it let the user change it through its PHPUnit config). So this change is just useless

@Seldaek
Copy link
Member

@Seldaek Seldaek commented Jun 10, 2011

@Seldaek Seldaek closed this Jun 10, 2011
naderman referenced this issue in naderman/composer Sep 25, 2011
naderman added a commit that referenced this issue Apr 29, 2012
Seldaek added a commit that referenced this issue May 28, 2012
@cevou cevou mentioned this pull request Sep 20, 2012
digitalkaoz pushed a commit to digitalkaoz/composer that referenced this issue Nov 22, 2013
digitalkaoz pushed a commit to digitalkaoz/composer that referenced this issue Nov 22, 2013
digitalkaoz pushed a commit to digitalkaoz/composer that referenced this issue Nov 22, 2013
@romeox6x66 romeox6x66 mentioned this pull request Jun 7, 2015
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 5, 2021
The default state for the `TransportException::$response` property is unset and - as testified by the notice in tests -, the `$response` may not be set, resulting in a `null` return value from `TransportException::getResponse()`.
Casting to string will preserve the existing behaviour.

Fixes:
```
Deprecation triggered by Composer\Test\Util\GitLabTest::testUsernamePasswordFailure:
json_decode(): Passing null to parameter composer#1 ($json) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 133)
1 src/Composer/Util/GitLab.php(133): json_decode(NULL, true)
2 tests/Composer/Test/Util/GitLabTest.php(108): Composer\Util\GitLab->authorizeOAuthInteractively('...', '...')
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 5, 2021
The default state for the `Perforce::$p4DepotType` property is unset and - as testified by the notice in tests -, the `$p4DepotType` may not be set, resulting in a `null` value being passed to the PHP native `strcmp()` function from within the `p4DepotType::isStream()` method.
Casting to string will preserve the existing behaviour.

Fixes various notices along the lines of:
```
Deprecation triggered by Composer\Test\Repository\Vcs\PerforceDriverTest::testInitializeCapturesVariablesFromRepoConfig:
strcmp(): Passing null to parameter composer#1 ($string1) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 163)
1 src/Composer/Util/Perforce.php(163): strcmp(NULL, '...')
2 src/Composer/Util/Perforce.php(169): Composer\Util\Perforce->isStream()
3 src/Composer/Util/Perforce.php(127): Composer\Util\Perforce->getStream()
4 src/Composer/Util/Perforce.php(191): Composer\Util\Perforce->getClient()
5 src/Composer/Util/Perforce.php(350): Composer\Util\Perforce->getP4ClientSpec()
6 src/Composer/Repository/Vcs/PerforceDriver.php(46): Composer\Util\Perforce->writeP4ClientSpec()
7 tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php(117): Composer\Repository\Vcs\PerforceDriver->initialize()
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 5, 2021
The default state for the `Perforce::$p4DepotType` property is unset and - as testified by the notice in tests -, the `$p4DepotType` may not be set, resulting in a `null` value being passed to the PHP native `strcmp()` function from within the `p4DepotType::isStream()` method.
Casting to string will preserve the existing behaviour.

Fixes various notices along the lines of:
```
Deprecation triggered by Composer\Test\Repository\Vcs\PerforceDriverTest::testInitializeCapturesVariablesFromRepoConfig:
strcmp(): Passing null to parameter composer#1 ($string1) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 163)
1 src/Composer/Util/Perforce.php(163): strcmp(NULL, '...')
2 src/Composer/Util/Perforce.php(169): Composer\Util\Perforce->isStream()
3 src/Composer/Util/Perforce.php(127): Composer\Util\Perforce->getStream()
4 src/Composer/Util/Perforce.php(191): Composer\Util\Perforce->getClient()
5 src/Composer/Util/Perforce.php(350): Composer\Util\Perforce->getP4ClientSpec()
6 src/Composer/Repository/Vcs/PerforceDriver.php(46): Composer\Util\Perforce->writeP4ClientSpec()
7 tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php(117): Composer\Repository\Vcs\PerforceDriver->initialize()
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 5, 2021
The default state for the `Perforce::$p4DepotType` property is unset and - as testified by the notice in tests -, the `$p4DepotType` may not be set, resulting in a `null` value being passed to the PHP native `strcmp()` function from within the `p4DepotType::isStream()` method.
Casting to string will preserve the existing behaviour.

Fixes various notices along the lines of:
```
Deprecation triggered by Composer\Test\Repository\Vcs\PerforceDriverTest::testInitializeCapturesVariablesFromRepoConfig:
strcmp(): Passing null to parameter composer#1 ($string1) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 163)
1 src/Composer/Util/Perforce.php(163): strcmp(NULL, '...')
2 src/Composer/Util/Perforce.php(169): Composer\Util\Perforce->isStream()
3 src/Composer/Util/Perforce.php(127): Composer\Util\Perforce->getStream()
4 src/Composer/Util/Perforce.php(191): Composer\Util\Perforce->getClient()
5 src/Composer/Util/Perforce.php(350): Composer\Util\Perforce->getP4ClientSpec()
6 src/Composer/Repository/Vcs/PerforceDriver.php(46): Composer\Util\Perforce->writeP4ClientSpec()
7 tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php(117): Composer\Repository\Vcs\PerforceDriver->initialize()
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 12, 2021
The return type of the `Rule::getRequiredPackage()` method effectively was `?string` as, if no matching reason was found, the function wasn't returning anything.

In PHP 8.1, this results in 97 notices along the lines of the below from existing tests:
```
Deprecation triggered by Composer\Test\DependencyResolver\SolverTest::testConflictResultEmpty:
strpos(): Passing null to parameter composer#1 ($haystack) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 111)
1 src/Composer/DependencyResolver/SolverProblemsException.php(111): strpos(NULL, '...')
2 src/Composer/DependencyResolver/SolverProblemsException.php(44): Composer\DependencyResolver\SolverProblemsException->hasExtensionProblems(Array)
3 tests/Composer/Test/DependencyResolver/SolverTest.php(659): Composer\DependencyResolver\SolverProblemsException->getPrettyString(Object(Composer\Repository\RepositorySet), Object(Composer\DependencyResolver\Request), Object(Composer\DependencyResolver\Pool), false)
....
```

Fixed by returning an empty string if no reason was matched.
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 12, 2021
…ly fix)

Not all tests in the `InstallerTest` class actually create a temporary directory and set the `$this->tempComposerHome` property.

Those tests which didn't, throw a notice in PHP 8.1.

Fixes 3 notices along the lines of:
```
Deprecation triggered by Composer\Test\InstallerTest::tearDown:
is_dir(): Passing null to parameter composer#1 ($filename) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 53)
1 tests/Composer/Test/InstallerTest.php(53): is_dir(NULL)
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 12, 2021
The default state for the `ProcessExecutor::$errorOutput` property is "not set" and if there has been no error during the execution of the process, it may well still be, resulting in the return value of `$this->process->getErrorOutput()` being `null`.

In that case, we may as well bypass the whole `foreach` as it will never match any of the recognized authentication failure messages.

Fixes a total of 5 deprecation notices along the lines of:
```
Deprecation triggered by Composer\Test\Downloader\GitDownloaderTest::testDownloadThrowsRuntimeExceptionIfGitCommandFails:
strpos(): Passing null to parameter composer#1 ($haystack) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 340)
1 src/Composer/Util/Git.php(340): strpos(NULL, '...')
2 src/Composer/Util/Git.php(200): Composer\Util\Git->isAuthenticationFailure('...', Array)
3 src/Composer/Downloader/GitDownloader.php(121): Composer\Util\Git->runCommand(Object(Closure), '...', NULL, true)
4 src/Composer/Downloader/VcsDownloader.php(137): Composer\Downloader\GitDownloader->doInstall(Object(Mock_PackageInterface_f8be9ebd), '...', '...')
5 tests/Composer/Test/Downloader/GitDownloaderTest.php(349): Composer\Downloader\VcsDownloader->install(Object(Mock_PackageInterface_f8be9ebd), '...')
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 12, 2021
The `LibraryInstallerTest::testUninstall()` method mocks a `Package` object, but did not set an expectation for a call to `getName()`, while that method _is_ called in the `LibraryInstaller::uninstall()` method.

Without expectation, the mock returns `null`, which was subsequently being passed on to `strpos()` leading to the below error.

Fixes:
```
Deprecation triggered by Composer\Test\Installer\LibraryInstallerTest::testUninstall:
strpos(): Passing null to parameter composer#1 ($haystack) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 202)
1 src/Composer/Installer/LibraryInstaller.php(202): strpos(NULL, '...')
2 vendor/react/promise/src/FulfilledPromise.php(28): Composer\Installer\LibraryInstaller->Composer\Installer\{closure}(NULL)
3 src/Composer/Installer/LibraryInstaller.php(208): React\Promise\FulfilledPromise->then(Object(Closure))
4 tests/Composer/Test/Installer/LibraryInstallerTest.php(221): Composer\Installer\LibraryInstaller->uninstall(Object(Mock_InstalledRepositoryInterface_e3699f95), Object(Mock_Package_e4571076))
...
```
jrfnl added a commit to jrfnl/composer that referenced this issue Aug 12, 2021
The default state for the `ProcessExecutor::$errorOutput` property is "not set" and if there has been no error during the execution of the process, it may well still be, resulting in the return value of `$this->process->getErrorOutput()` being `null`.

In that case, we may as well bypass the whole `foreach` as it will never match any of the recognized authentication failure messages.

Includes correcting the return type for the `ProcessExecutor::getErrorOutput()` method.

There are several alternative solutions possible here:
* Set a default value for the `ProcessExecutor::$errorOutput` property of an empty string.
* Check within the `ProcessExecutor::getErrorOutput()` method whether the property is set and if not, return an empty string.

Not sure what is the best solution, please provide guidance.

Fixes a total of 5 deprecation notices along the lines of:
```
Deprecation triggered by Composer\Test\Downloader\GitDownloaderTest::testDownloadThrowsRuntimeExceptionIfGitCommandFails:
strpos(): Passing null to parameter composer#1 ($haystack) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 340)
1 src/Composer/Util/Git.php(340): strpos(NULL, '...')
2 src/Composer/Util/Git.php(200): Composer\Util\Git->isAuthenticationFailure('...', Array)
3 src/Composer/Downloader/GitDownloader.php(121): Composer\Util\Git->runCommand(Object(Closure), '...', NULL, true)
4 src/Composer/Downloader/VcsDownloader.php(137): Composer\Downloader\GitDownloader->doInstall(Object(Mock_PackageInterface_f8be9ebd), '...', '...')
5 tests/Composer/Test/Downloader/GitDownloaderTest.php(349): Composer\Downloader\VcsDownloader->install(Object(Mock_PackageInterface_f8be9ebd), '...')
...
```
glaubinix added a commit to glaubinix/composer that referenced this issue Feb 9, 2022
glaubinix added a commit to glaubinix/composer that referenced this issue Feb 9, 2022
Seldaek pushed a commit that referenced this issue Feb 9, 2022
glaubinix added a commit to glaubinix/composer that referenced this issue Jun 24, 2022
glaubinix added a commit to glaubinix/composer that referenced this issue Jun 24, 2022
glaubinix added a commit to glaubinix/composer that referenced this issue Jun 24, 2022
Seldaek pushed a commit that referenced this issue Jun 24, 2022
ktomk added a commit to ktomk/composer that referenced this issue Jun 30, 2022
Fix string type requirement in case of NULL value:

    [TypeError]                                                                                                                                                                  
    Composer\Command\InitCommand::parseAuthorString(): Argument composer#1 ($author) must be of type string, null given, called in phar:///composer.phar/src/Composer/Command/InitCommand.php on line 345
Seldaek pushed a commit that referenced this issue Jul 1, 2022
Fix string type requirement in case of NULL value:

    [TypeError]                                                                                                                                                                  
    Composer\Command\InitCommand::parseAuthorString(): Argument #1 ($author) must be of type string, null given, called in phar:///composer.phar/src/Composer/Command/InitCommand.php on line 345
Seldaek pushed a commit that referenced this issue Jul 1, 2022
Fix string type requirement in case of NULL value:

    [TypeError]                                                                                                                                                                  
    Composer\Command\InitCommand::parseAuthorString(): Argument #1 ($author) must be of type string, null given, called in phar:///composer.phar/src/Composer/Command/InitCommand.php on line 345
Seldaek pushed a commit that referenced this issue Jul 1, 2022
Fix string type requirement in case of NULL value:

    [TypeError]                                                                                                                                                                  
    Composer\Command\InitCommand::parseAuthorString(): Argument #1 ($author) must be of type string, null given, called in phar:///composer.phar/src/Composer/Command/InitCommand.php on line 345
fluffycondor referenced this issue in fluffycondor/composer Jul 4, 2022
Deprecation Notice: trim(): Passing null to parameter #1 ($string) of type string is deprecated in phar:///usr/bin/composer/src/Composer/Util/GitHub.php:103
fluffycondor referenced this issue in fluffycondor/composer Jul 4, 2022
Deprecation Notice: trim(): Passing null to parameter #1 ($string) of type string is deprecated in phar:///usr/bin/composer/src/Composer/Util/GitHub.php:103
Seldaek pushed a commit that referenced this issue Jul 5, 2022
Deprecation Notice: trim(): Passing null to parameter #1 ($string) of type string is deprecated in phar:///usr/bin/composer/src/Composer/Util/GitHub.php:103
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

Successfully merging this pull request may close these issues.

None yet

3 participants