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

[3.x]: php craft console command fails with Invalid path alias: @ error #11492

Closed
davola opened this issue Jun 22, 2022 · 4 comments
Closed

[3.x]: php craft console command fails with Invalid path alias: @ error #11492

davola opened this issue Jun 22, 2022 · 4 comments

Comments

@davola
Copy link

davola commented Jun 22, 2022

What happened?

Description

When trying to see the available list of commands we have in craft, it fails with the following error:

Exception 'yii\base\InvalidArgumentException' with message 'Invalid path alias: @' in /app/vendor/yiisoft/yii2/BaseYii.php:154

According with the \yii\base\Module::getControllerPath method help docs

# vendor/yiisoft/yii2/base/Module.php

    /**
     * Returns the directory that contains the controller classes according to [[controllerNamespace]].
     * Note that in order for this method to return a value, you must define
     * an alias for the root namespace of [[controllerNamespace]].
     * @return string the directory that contains the controller classes.
     * @throws InvalidArgumentException if there is no alias defined for the root namespace of [[controllerNamespace]].
     */
    public function getControllerPath()

it seems we fail to provide the needed alias namespace for this to work properly.

Steps to reproduce

  1. goto your project container
  2. goto craft root directory
  3. type php craft and hit enter

Expected behavior

It should list all the available commands that Craft has

Actual behavior

It shows the following YII error:

Exception 'yii\base\InvalidArgumentException' with message 'Invalid path alias: @'

in /app/vendor/yiisoft/yii2/BaseYii.php:154

Stack trace:
#0 /app/vendor/yiisoft/yii2/base/Module.php(261): yii\BaseYii::getAlias('@')
#1 /app/vendor/yiisoft/yii2/console/controllers/HelpController.php(245): yii\base\Module->getControllerPath()
#2 /app/vendor/yiisoft/yii2/console/controllers/HelpController.php(240): yii\console\controllers\HelpController-> >getModuleCommands(Object(modules\customRedactorConfig\Module))
#3 /app/vendor/yiisoft/yii2/console/controllers/HelpController.php(172): yii\console\controllers\HelpController->getModuleCommands(Object(craft\console\Application))
#4 /app/vendor/yiisoft/yii2/console/controllers/HelpController.php(192): yii\console\controllers\HelpController->getCommands()
#5 /app/vendor/yiisoft/yii2/console/controllers/HelpController.php(78): yii\console\controllers\HelpController->getCommandDescriptions()
#6 [internal function]: yii\console\controllers\HelpController->actionList()
#7 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#9 /app/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction('list', Array)
#10 /app/vendor/yiisoft/yii2/base/Module.php(552): yii\console\Controller->runAction('list', Array)
#11 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('help/list', Array)
#12 /app/vendor/craftcms/cms/src/console/Application.php(89): yii\console\Application->runAction('help/list', Array)
#13 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('help/list', Array)
#14 /app/vendor/craftcms/cms/src/console/Application.php(118): yii\console\Application->handleRequest(Object(craft\console\Request))
#15 /app/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#16 /app/craft(27): yii\base\Application->run()
#17 {main}

Craft CMS version

Craft Pro 3.7.44

PHP version

8.0.20

Operating system and version

Linux 4.19.104-microsoft-standard

Database type and version

postgres

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-35)

Installed plugins and versions

  • Amazon S3 1.3.0
  • Colour Swatches 1.6.0
  • Feed Me 4.5.3
  • Field Manager 2.2.4
  • Google Cloud Storage 1.4.1
  • Icon Picker 1.1.13
  • Neo 2.13.11
  • oEmbed 1.3.15
  • Publisher 2.1.0
  • Redactor 2.10.8
  • SEOmatic 3.4.31
  • Super Table 2.7.2
@davola davola changed the title [3.x]: php craft console command help fails with empty alias error [3.x]: php craft console command fails with Invalid path alias: @ error Jun 22, 2022
@brandonkelly
Copy link
Member

From the stack trace, it looks like the issue is coming from modules\customRedactorConfig\Module. Can you post that module’s code?

@davola
Copy link
Author

davola commented Jun 23, 2022

oh! That module trace skipped my eyes.

here is the code

# modules\customRedactorConfig\Module.php

<?php
namespace modules\customRedactorConfig;

use craft\redactor\events\RegisterLinkOptionsEvent;
use craft\redactor\Field as RedactorField;
use yii\base\Event;

class Module extends \yii\base\Module
{
    /**
     * Initializes the module.
     */
    public function init()
    {
        // Remove "Link to..." Redactor links
        Event::on(
            RedactorField::class,
            RedactorField::EVENT_REGISTER_LINK_OPTIONS,
            function(RegisterLinkOptionsEvent $event) {

                // Only apply to a specific Redactor config
                if ('OnlyDefinedLinks.json' == $event->sender->redactorConfig) {

                    // Remove Craft's injected links
                    $event->linkOptions = [];

                }

            }
        );
    }
}

Thank you!

@davola
Copy link
Author

davola commented Jun 23, 2022

Oh! You are a genius @brandonkelly. You were right, the controller namespace initialization was missing on this Module.

I have added the following on top and it works perfect now:

        if (\Craft::$app->getRequest()->getIsConsoleRequest()) {
            $this->controllerNamespace = 'modules\\console\\controllers';
        } else {
            $this->controllerNamespace = 'modules\\controllers';
        }

Sorry for the inconvenience and thank you so much for dedicating the time to see this.
Your product Craft is awesome! 💪

Closing this now,
Thanks! 🙏

@davola davola closed this as completed Jun 23, 2022
@brandonkelly
Copy link
Member

Glad you got it sorted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants