From 33c05c5d26f2cf03e8cc3667301ac15c2b313138 Mon Sep 17 00:00:00 2001 From: Michael Karlesky Date: Tue, 29 Oct 2024 13:47:24 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Replaced=20Rake=20exception=20with?= =?UTF-8?q?=20our=20own?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tasks not found produced Rake-specific exception that is confusing with all the other work to remove Rake from the direct experience of end users as well as beginning the process to move away from Rake. New exception message suppresses Rake messaging. --- bin/cli_helper.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bin/cli_helper.rb b/bin/cli_helper.rb index c518abf3..a73bc5e5 100644 --- a/bin/cli_helper.rb +++ b/bin/cli_helper.rb @@ -6,7 +6,10 @@ # ========================================================================= require 'app_cfg' -require 'ceedling/constants' # From Ceedling application + +# From Ceedling application +require 'ceedling/constants' +require 'ceedling/exceptions' class CliHelper @@ -246,7 +249,26 @@ def print_rake_tasks() def run_rake_tasks(tasks) Rake.application.collect_command_line_tasks( tasks ) - Rake.application.top_level() + + # Replace Rake's exception message to reduce any confusion + begin + Rake.application.top_level() + + rescue RuntimeError => ex + # Check if exception contains an unknown Rake task message + matches = ex.message.match( /how to build task '(.+)'/i ) + + # If it does, replacing the message with our own + if matches.size == 2 + message = "Unrecognized build task '#{matches[1]}'. List available build tasks with `ceedling help`." + raise CeedlingException.new( message ) + + # Otherwise, just re-raise + else + raise + end + end + end