{
  "id": "ros2/launch-file-substitution-undefined-variable",
  "signature": "ros2 launch: Substitution error: Undefined variable 'my_var' in launch file",
  "signature_zh": "ros2启动：替换错误：启动文件中未定义变量'my_var'",
  "regex": "Substitution error: Undefined variable",
  "domain": "ros2",
  "category": "config_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "启动文件使用了未声明或未作为参数传递的变量替换（例如$(var my_var)），导致解析失败。",
  "versions": [
    {
      "version": "Humble",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Iron",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Jazzy",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Rolling",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using $(env my_var) instead of $(var my_var) without setting environment variable",
      "why_fails": "Substitution type mismatch; $(env) expects an environment variable, not a launch argument.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding the variable directly in the launch file without DeclareLaunchArgument",
      "why_fails": "ROS2 launch requires explicit declaration; inline usage without declaration still fails.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting the variable in a separate YAML config file without including it",
      "why_fails": "YAML config files aren't automatically loaded; they must be included via IncludeLaunchDescription.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add a DeclareLaunchArgument for the variable in the launch file.",
      "success_rate": 0.95,
      "how": "Add a DeclareLaunchArgument for the variable in the launch file.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Pass the variable as a command-line argument when launching.",
      "success_rate": 0.9,
      "how": "Pass the variable as a command-line argument when launching.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a default value in the substitution to avoid undefined errors.",
      "success_rate": 0.85,
      "how": "Use a default value in the substitution to avoid undefined errors.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Add a DeclareLaunchArgument for the variable in the launch file.",
    "Pass the variable as a command-line argument when launching.",
    "Use a default value in the substitution to avoid undefined errors."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.ros.org/en/rolling/Tutorials/Intermediate/Launch/Using-Substitutions.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-07-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}