# ros2 launch: Substitution error: Undefined variable 'my_var' in launch file

- **ID:** `ros2/launch-file-substitution-undefined-variable`
- **Domain:** ros2
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A launch file uses a variable substitution (e.g., $(var my_var)) that hasn't been declared or passed as an argument, causing a parse failure.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Humble | active | — | — |
| Iron | active | — | — |
| Jazzy | active | — | — |
| Rolling | active | — | — |

## Workarounds

1. **Add a DeclareLaunchArgument for the variable in the launch file.** (95% success)
   ```
   Add a DeclareLaunchArgument for the variable in the launch file.
   ```
2. **Pass the variable as a command-line argument when launching.** (90% success)
   ```
   Pass the variable as a command-line argument when launching.
   ```
3. **Use a default value in the substitution to avoid undefined errors.** (85% success)
   ```
   Use a default value in the substitution to avoid undefined errors.
   ```

## Dead Ends

- **Using $(env my_var) instead of $(var my_var) without setting environment variable** — Substitution type mismatch; $(env) expects an environment variable, not a launch argument. (60% fail)
- **Adding the variable directly in the launch file without DeclareLaunchArgument** — ROS2 launch requires explicit declaration; inline usage without declaration still fails. (70% fail)
- **Setting the variable in a separate YAML config file without including it** — YAML config files aren't automatically loaded; they must be included via IncludeLaunchDescription. (50% fail)
