cedaro / satispress

Expose installed WordPress plugins and themes as Composer packages.
508 stars 51 forks source link

Fatal error: Uncaught TypeError: Return value of SatisPress\Logger::format_exception() must be of the type string, bool returned #158

Closed JanThiel closed 3 years ago

JanThiel commented 3 years ago

WP 5.7.1 SatisPress 1.0.1 PHP 7.4.16 WP-CLI 2.4.0

Tried to install a Plugin (update) via WP-CLI:

wp plugin install --force https://yoast.com/app/uploads/2021/04/wordpress-seo-premium-16.1.zip

This error comes up:

Fatal error: Uncaught TypeError: Return value of SatisPress\Logger::format_exception() must be of the type string, bool returned in /web/wp-content/plugins/satispress/src/Logger.php:153
Stack trace:
#0 /web/wp-content/plugins/satispress/src/Logger.php(130): SatisPress\Logger->format_exception(Object(SatisPress\Exception\FileDownloadFailed))
#1 /web/wp-content/plugins/satispress/src/Logger.php(83): SatisPress\Logger->format('Error archiving...', Array)
#2 /web/wp-content/plugins/wp-rocket/vendor/psr/log/Psr/Log/AbstractLogger.php(69): SatisPress\Logger->log('error', 'Error archiving...', Array)
#3 /web/wp-content/plugins/satispress/src/Provider/PackageArchiver.php(182): Psr\Log\AbstractLogger->error('Error archiving...', Array)
#4 /web/wp-includes/class-wp-hook.php(294): SatisPress\Provider\PackageArchiver->archive_updates(Object(stdC in /web/wp-content/plugins/satispress/src/Logger.php on line 153
JanThiel commented 3 years ago

https://github.com/cedaro/satispress/blob/a5e7afb3cf027260aa0644c171ecba71cca76bbb/src/Logger.php#L144-L155

Removing the trace from the json encoding solved the issue.

        /**
         * Format an exception.
         *
         * @since 0.4.0
         *
         * @param Exception $e Exception.
         * @return string
         */
        protected function format_exception( Exception $e ): string {
                return wp_json_encode(
                        [
                                'message' => $e->getMessage(),
                                'code'    => $e->getCode(),
                                'file'    => $e->getFile(),
                                'line'    => $e->getLine(),
                        ],
                        \JSON_UNESCAPED_SLASHES
                );
        }