From 6f2ad38324fe3776ea86c4d15e1c873209dea32a Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 15 Oct 2011 01:09:26 -0700 Subject: [PATCH] Improve error message on empty command (Issue #299) --- lib/pry/helpers/command_helpers.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 4340f67c..11faf4cd 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -32,14 +32,18 @@ class Pry if (meth = Pry::Method.from_str(name, target, opts)) set_file_and_dir_locals(meth.source_file) meth + elsif name + command_error("The method '#{name}' could not be found.", omit_help) else - # FIXME: better/more accurate error handling - message = "The method '#{name}' could not be found." - message << " Type `#{command_name} --help` for help." unless omit_help - raise CommandError, message + command_error("No method name given, and context is not a method.", omit_help) end end + def command_error(message, omit_help) + message += " Type `#{command_name} --help` for help." unless omit_help + raise CommandError, message + end + def make_header(meth, content=meth.source) header = "\n#{Pry::Helpers::Text.bold('From:')} #{meth.source_file} "