Closed xinningsu closed 2 years ago
What version of Craft CMS, and what version of Retour?
Craft CMS: 3.7.46 Retour: 3.1.73
You should be able to fix this by updating to the latest version of craft-plugin-vite by doing:
composer update nystudio107/craft-plugin-vite
@khalwat thanks for your help, but unfortunately, it doesn't work. I don't use Vite, and this url hardcode here is not accessible: https://github.com/nystudio107/craft-retour/blob/develop/src/Retour.php#L145
2022-08-24 11:22:54 [-][-][mec5g510jc1gmjdq7r51m74m2i][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
You don't use Vite, but my plugin does.
Where are you seeing this error? In logs, or elsewhere?
The code specifically turns off HTTP_ERRORS:
...and also catches any exceptions that might be thrown:
What version of Guzzle is installed in your setup?
oooooo, I think I know what might be going on here! Give me a moment
Addressed in 1.0.28: https://github.com/nystudio107/craft-plugin-vite/releases/tag/1.0.28 & 4.0.4: https://github.com/nystudio107/craft-plugin-vite/releases/tag/4.0.4
To update, do this again:
composer update nystudio107/craft-plugin-vite
...and let me know how you go
@khalwat Sorry for late reply, have been busy these days.
I have Guzzle 7.4.5, I saw the error in logs.
After I upgrade nystudio107/craft-plugin-vite to 1.0.28, still not working. but a litter different, another plugin craft-typogrify
involved. Strange thing is this happens only when I create a new site in cms and visit the new site url first time. after refreshing the page, the error is gone.
2022-08-29 12:56:06 [-][1][0svnabdjqjjsp9688hv5me6c7s][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
2022-08-29 12:56:06 [-][1][0svnabdjqjjsp9688hv5me6c7s][error][LogicException] LogicException: Unable to register extension "nystudio107\typogrify\twigextensions\TypogrifyTwigExtension" as extensions have already been initialized. in /app/vendor/twig/twig/src/ExtensionSet.php:145
Stack trace:
#0 /app/vendor/twig/twig/src/Environment.php(701): Twig\ExtensionSet->addExtension()
#1 /app/vendor/craftcms/cms/src/web/View.php(362): Twig\Environment->addExtension()
#2 /app/vendor/nystudio107/craft-typogrify/src/Typogrify.php(62): craft\web\View->registerTwigExtension()
#3 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): nystudio107\typogrify\Typogrify->init()
#4 /app/vendor/yiisoft/yii2/base/Module.php(161): yii\base\BaseObject->__construct()
#5 /app/vendor/craftcms/cms/src/base/Plugin.php(115): yii\base\Module->__construct()
#6 [internal function]: craft\base\Plugin->__construct()
#7 /app/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs()
#8 /app/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build()
#9 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get()
#10 /app/vendor/craftcms/cms/src/Craft.php(61): yii\BaseYii::createObject()
#11 /app/vendor/craftcms/cms/src/services/Plugins.php(948): Craft::createObject()
#12 /app/vendor/craftcms/cms/src/services/Plugins.php(232): craft\services\Plugins->createPlugin()
#13 /app/vendor/craftcms/cms/src/services/Plugins.php(797): craft\services\Plugins->loadPlugins()
#14 /app/modules/sealink/Module.php(60): craft\services\Plugins->isPluginInstalled()
#15 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): modules\sealink\Module->init()
#16 /app/vendor/yiisoft/yii2/base/Module.php(161): yii\base\BaseObject->__construct()
#17 [internal function]: yii\base\Module->__construct()
#18 /app/vendor/yiisoft/yii2/di/Container.php(411): ReflectionClass->newInstanceArgs()
#19 /app/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build()
#20 /app/vendor/yiisoft/yii2/BaseYii.php(345): yii\di\Container->get()
#21 /app/vendor/yiisoft/yii2/base/Module.php(445): yii\BaseYii::createObject()
#22 /app/vendor/yiisoft/yii2/base/Application.php(313): yii\base\Module->getModule()
#23 /app/vendor/craftcms/cms/src/web/Application.php(116): yii\base\Application->bootstrap()
#24 /app/vendor/yiisoft/yii2/base/Application.php(271): craft\web\Application->bootstrap()
#25 /app/vendor/craftcms/cms/src/web/Application.php(93): yii\base\Application->init()
#26 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#27 /app/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct()
#28 [internal function]: yii\base\Application->__construct()
#29 /app/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs()
#30 /app/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build()
#31 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get()
#32 /app/vendor/craftcms/cms/src/Craft.php(61): yii\BaseYii::createObject()
#33 /app/vendor/craftcms/cms/bootstrap/bootstrap.php(247): Craft::createObject()
#34 /app/vendor/craftcms/cms/bootstrap/web.php(51): require('...')
#35 /app/web/index.php(81): require('...')
#36 {main}
I noticed the plugin catches exceptions, but better avoid the exception instead of catching it every time?
Such as here: https://github.com/nystudio107/craft-retour/blob/4.0.2/src/Retour.php#L128
If we can custom useDevServer
to false, I think the problem will be gone, not sure if new problem will be introduced.
Well, so here's the thing that I don't understand. It should automatically be setting useDevServer
to false
already:
https://github.com/nystudio107/craft-plugin-vite/blob/develop/src/services/VitePluginService.php#L54
...unless somehow, for some weird, reason, you have the VITE_PLUGIN_DEVSERVER
environment variable set?
@khalwat No, I don't have VITE_PLUGIN_DEVSERVER
set.
And that part of code is not executed, it's return here: https://github.com/nystudio107/craft-plugin-vite/blob/develop/src/services/VitePluginService.php#L52
Oh nice catch, I was completely overlooking that! That's the root problem here then, though I have no idea how creating a new site could result in a non-CP request!
Creating a new site won't have the issue, only when visit the new site first time, such as: https://localhost/new-site-url/
Addressed in: https://github.com/nystudio107/craft-plugin-vite/releases/tag/1.0.29 & https://github.com/nystudio107/craft-plugin-vite/releases/tag/4.0.5
To update, do this again:
composer update nystudio107/craft-plugin-vite
...and let me know how you go. I'm feeling good about this one, thanks for your patience.
@khalwat I have craft-plugin-vite
upgraded to 1.0.29, but the error still appears in my log file:
2022-08-29 15:24:03 [-][1][vk5fspj4d9li6krlbdgn1goj69][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
But if I manually change this value to false, won't see the error.
every request will add a record to log file, although the page is not 500.
2022-08-29 15:52:51 [-][1][-][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
2022-08-29 15:53:15 [-][1][-][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
2022-08-29 15:53:27 [-][1][-][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
2022-08-29 15:53:51 [-][1][-][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
2022-08-29 15:53:55 [-][1][-][error][nystudio107\pluginvite\helpers\FileHelper::fetchResponse] cURL error 6: Could not resolve host: craft-retour-buildchain (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://craft-retour-buildchain:3001/__vite_ping
Very strange, because it should be setting that value to false
here:
https://github.com/nystudio107/craft-plugin-vite/blob/develop/src/services/VitePluginService.php#L52
@khalwat yep, I can confirm that part of code has been executed. so I guess maybe there are multiple instances of VitePluginService
. some instances with useDevServer
= true. this can explain why I manually change this value to false, won't see the error.
Each plugin I write will have an instance of VitePluginService
but they all are executing the same code path, which should set useDevServer
to false
if that environment variable is not there.
Very puzzling.
Okay so I managed to reproduce this locally, here's what was happening:
public function init()
{
parent::init();
// See if the $pluginDevServerEnvVar env var exists, and if not, don't run off of the dev server
$useDevServer = (bool)App::env($this->pluginDevServerEnvVar);
if ($useDevServer === false) {
$this->useDevServer = false;
}
This is the code from VitePluginService... the problem here is the parent::init()
which is called first (as you normally would using typical PHP inheritance patterns). This call to parent::init()
is what is attempting to ping the dev server:
public function init()
{
parent::init();
// Do nothing for console requests
$request = Craft::$app->getRequest();
if ($request->getIsConsoleRequest()) {
return;
}
// Our component is lazily loaded, so the View will be instantiated by now
if ($this->devServerRunning() && Craft::$app->getConfig()->getGeneral()->devMode) {
Craft::$app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']);
}
}
The call to devServerRunning()
is what triggers it. At this point, useDevServer
still has not properly been set to false
because that section of VitePluginService::init()
has not been executed yet. So the environment variable check just needs to be done before we call parent::init()
Addressed in: https://github.com/nystudio107/craft-plugin-vite/releases/tag/1.0.30 & https://github.com/nystudio107/craft-plugin-vite/releases/tag/4.0.6
To update, do this again:
composer update nystudio107/craft-plugin-vite
...and let me know how you go. This fixes it locally in my testing.
@khalwat The problem has been completely solved, thanks.
Thank you for your help, and for your patience @xinningsu ! 非常感谢
Question
I have multiple sites in caftcms, after I ceated a new site, and open the homepage of the new site, I got this error:
looks another dependency plugin
nystudio107/craft-plugin-vite
called a non existent hostcraft-retour-buildchain
Additional context