From 95d4699c7b26cba0c634edd2865fe7e998d4b497 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Fri, 26 Aug 2022 12:58:19 -0300 Subject: [PATCH] Remove comments from yaml file before applying substitutions Signed-off-by: Ivan Santiago Paunovic --- launch_ros/launch_ros/parameter_descriptions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/launch_ros/launch_ros/parameter_descriptions.py b/launch_ros/launch_ros/parameter_descriptions.py index 3d67c4d7e..9debf7b48 100644 --- a/launch_ros/launch_ros/parameter_descriptions.py +++ b/launch_ros/launch_ros/parameter_descriptions.py @@ -240,7 +240,13 @@ def evaluate(self, context: LaunchContext) -> Path: with open(param_file_path, 'r') as f, NamedTemporaryFile( mode='w', prefix='launch_params_', delete=False ) as h: - parsed = perform_substitutions(context, parse_substitution(f.read())) + try: + file_without_comments = yaml.safe_dump(yaml.safe_load(f.read())) + except Exception: + raise SubstitutionFailure( + 'The parameter file is not a valid yaml file, ' + 'before applying substitutions') + parsed = perform_substitutions(context, parse_substitution(file_without_comments)) try: yaml.safe_load(parsed) except Exception: