# ros2 launch: Substitution error: argument 'my_arg' not found in launch configuration

- **ID:** `ros2/ros2-launch-arg-substitution-not-found`
- **Domain:** ros2
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A launch file uses $(var my_arg) or similar substitution for an argument that was never declared with DeclareLaunchArgument.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ROS2 Humble (launch 1.0.0) | active | — | — |
| ROS2 Iron (launch 1.1.0) | active | — | — |
| ROS2 Rolling (launch 1.2.0) | active | — | — |

## Workarounds

1. **Add a DeclareLaunchArgument for 'my_arg' in the launch file before using it: from launch.actions import DeclareLaunchArgument; ld.add_action(DeclareLaunchArgument('my_arg', default_value='default'))** (95% success)
   ```
   Add a DeclareLaunchArgument for 'my_arg' in the launch file before using it: from launch.actions import DeclareLaunchArgument; ld.add_action(DeclareLaunchArgument('my_arg', default_value='default'))
   ```
2. **If the argument is optional, use a conditional substitution: $(var my_arg 'default_value') to provide a fallback.** (85% success)
   ```
   If the argument is optional, use a conditional substitution: $(var my_arg 'default_value') to provide a fallback.
   ```

## Dead Ends

- **Add the argument to the launch command line without declaring it in the file** — Arguments passed on the command line must match a declared argument; otherwise, ros2 launch ignores them. (80% fail)
- **Use $(env my_arg) instead of $(var my_arg)** — Environment variables are not the same as launch arguments; the substitution syntax is different. (90% fail)
