Skip to content

new error importing symfony console commands #779

@tacman

Description

@tacman

I'm getting an error that I haven't seen before, castor 1.1

My castor file has

import('src/Command/LoadCongressCommand.php');
import('src/Command/LoadDummyCommand.php');
import('src/Command/JeopardyCommand.php');

The command itself looks normal

<?php

namespace App\Command;

use App\Entity\Official;
use App\Entity\Term;
use App\Repository\OfficialRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\String\Slugger\AsciiSlugger;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Castor\Attribute\AsSymfonyTask;

#[AsCommand('init:congress', 'Load the congressional data')]
#[AsSymfonyTask('load:congress')]
final class LoadCongressCommand
{
    public function __construct(
        private readonly ValidatorInterface  $validator,
        private readonly CacheInterface      $cache,
        private EntityManagerInterface       $manager,
        private OfficialRepository           $officialRepository,
        ?string                              $name = null)
    {
//        parent::__construct($name);
    }

    public function __invoke(
        SymfonyStyle   $io,
        #[Option(description: 'reload the json even if already in the cache')] bool $refresh = false,
        #[Option(description: 'max records to load')] int $limit=0,
        #[Option(description: 'purge database first')] bool $purge=false,
        #[Option(description: 'dispatch request for details')] bool $details=false,
        #[Option(description: 'url to json')] string $url='https://unitedstates.github.io/congress-legislators/legislators-current.json',
    ): int
    {
        if ($purge) {
            $count = $this->officialRepository->createQueryBuilder('o')
                ->delete()
                ->getQuery()
                ->execute();

When I remove the attribute, it works

//#[AsSymfonyTask('load:congress')]

castor --help

In LockRegistry.php line 111:
                                                                         
  Function "App\Command\LoadDummyCommand()" is not properly configured:  
  Could not run the Symfony console.                                     
  Defined in "src/Command/LoadDummyCommand.php" line 23.                 
                                                                         

In Process.php line 275:
                                                                                                                                                                                     
  The command "'bin/console' '--format=json'" failed.                                                                                                                                
                                                                                                                                                                                     
  Exit Code: 1(General error)                                                                                                                                                        
                                                                                                                                                                                     
  Working directory: /home/tac/g/sites/meili                                                                                                                                         
                                                                                                                                                                                     
  Output:                                                                                                                                                                            
  ================                                                                                                                                                                   
                                                                                                                                                                                     
  ✖ Console error:                                                                                                                                                                   
  Symfony\Component\Console\Exception\LogicException                                                                                                                                 
  An option with shortcut "e" already exists.                                                                                                                                        
                                                                                                                                                                                     
                                                                                                                                                                                     
  Error Output:                                                                                                                                                                      
  ================                                                                                                                                                                   
  {"message":"Error thrown while running command \"--format=json\". Message: \"An option with shortcut \"e\" already exists.\"","context":{"exception":{"class":"Symfony\\Component  
  \\Console\\Exception\\LogicException","message":"An option with shortcut \"e\" already exists.","code":1,"file":"/home/tac/g/sites/meili/vendor/symfony/console/Input/InputDefini  
  tion.php:229"},"command":"--format=json","message":"An option with shortcut \"e\" already exists."},"level":500,"level_name":"CRITICAL","channel":"console","datetime":"2026-01-2  
  1T10:25:24.125911+00:00","extra":{}}                                                                                                                                               
  10:25:24 CRITICAL  [console] Error thrown while running command "--format=json". Message: "An option with shortcut "e" already exists." ["exception" => Symfony\Component\Console  
  \Exception\LogicException { …},"command" => "--format=json","message" => "An option with shortcut "e" already exists."]                                                            
  {"message":"Command \"--format=json\" exited with code \"1\"","context":{"command":"--format=json","code":1},"level":100,"level_name":"DEBUG","channel":"console","datetime":"202  
  6-01-21T10:25:24.136905+00:00","extra":{}}                                                                                                                                         
                                                                                                                                                                                     
                                                                                                                                                                                     
    An option with shortcut "e" already exists.                                                                                                                                      
                                                                                                                                                                                     
                                                                                                                                                                                     
  list [--raw] [--format FORMAT] [--short] [--] [<namespace>]                                                                                                                        
                                                                                                                                                                                     

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions