{"record":{"id":"fc284b87f2181ace","repo":"composer/composer","slug":"unknown-action-action-use-add-source","errorCode":null,"errorMessage":"Unknown action \"{action}\". Use add-source.","messagePattern":"Unknown action \"(.+?)\"\\. Use add-source\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/PolicyCommand.php","lineNumber":122,"sourceCode":"\n                foreach ($currentSources as $existing) {\n                    if (is_array($existing)\n                        && ($existing['type'] ?? null) === $sourceConfig['type']\n                        && ($existing['url'] ?? null) === ($sourceConfig['url'] ?? null)\n                    ) {\n                        $this->getIO()->write('<info>Source '.$sourceConfig['url'].' already present in policy '.$listName.'</info>');\n\n                        return 0;\n                    }\n                }\n\n                $currentSources[] = $sourceConfig;\n                $this->configSource->addConfigSetting('policy.'.$listName.'.sources', $currentSources);\n\n                return 0;\n\n            default:\n                throw new \\InvalidArgumentException('Unknown action \"'.$action.'\". Use add-source.');\n        }\n    }\n\n    private function assertCustomListName(string $name): void\n    {\n        if (in_array($name, PolicyConfig::BUILTIN_LIST_NAMES, true)) {\n            throw new \\RuntimeException('Built-in dependency policy \"'.$name.'\" does not support sources. Use `composer config policy.'.$name.'.<field>` to configure it.');\n        }\n\n        $error = PolicyConfig::getFutureReservedListNameError($name);\n        if ($error !== null) {\n            throw new \\RuntimeException($error);\n        }\n\n        if ($name === '' || strpos($name, '.') !== false) {\n            throw new \\RuntimeException('Invalid dependency policy name \"'.$name.'\".');\n        }\n    }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Command/PolicyCommand.php#L104-L140","documentation":"Thrown by `composer policy` (PolicyCommand.php:122, the `default` switch arm) when the required `action` argument is anything other than `add-source`. The command currently supports only one sub-action; any other value (including typos or plausible-but-unimplemented actions like `remove`, `list`, `enable`) lands in the default arm and is rejected with an `InvalidArgumentException`.","triggerScenarios":"Running `composer policy remove my-policy`, `composer policy list`, `composer policy show`, or any misspelling such as `composer policy addsource` or `composer policy add_source`. The `action` argument is `REQUIRED` so it cannot be omitted, but it is not constrained to a value-set at the input layer — only validated inside `execute()`.","commonSituations":"Assuming the policy command mirrors the repo command's sub-actions (list/add/remove); typoing `add-source`; using an older/newer Composer version whose supported actions differ; scripting against an action that was renamed.","solutions":["Use the only supported action: `composer policy add-source <name> <type> <url>`.","Check the exact spelling — it is `add-source` with a hyphen, not `addsource` or `add_source`.","Run `composer policy --help` to list the accepted action value for your Composer build."],"exampleFix":"// before\ncomposer policy remove my-policy\n// after\ncomposer policy add-source my-policy url https://example.org/pkgs.json","handlingStrategy":"validation","validationCode":"$allowedActions = ['add-source'];\nif (!in_array(strtolower($action), $allowedActions, true)) {\n    fwrite(STDERR, 'Unknown action. Supported: ' . implode(', ', $allowedActions) . PHP_EOL);\n    exit(2);\n}","typeGuard":"function isSupportedPolicyAction(string $action): bool {\n    return in_array(strtolower($action), ['add-source'], true);\n}","tryCatchPattern":null,"preventionTips":["Pin the action spelling to `add-source` (hyphenated) in scripts.","Run `composer policy --help` after upgrading Composer to check supported actions."],"tags":["composer","policy","cli","invalid-argument"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}