Rework fail command not to display command call stack

`fail` triggers "expected" errors, and hence should just display
the provided message.
This commit is contained in:
Maxime Coste 2018-05-26 13:07:03 +10:00
parent 54b62cbef7
commit 68fb3ba88f
3 changed files with 14 additions and 3 deletions

View File

@ -425,10 +425,15 @@ void CommandManager::execute_single_command(CommandParameters params,
command_it->value.param_desc); command_it->value.param_desc);
command_it->value.func(parameter_parser, context, shell_context); command_it->value.func(parameter_parser, context, shell_context);
} }
catch (failure& error)
{
throw;
}
catch (runtime_error& error) catch (runtime_error& error)
{ {
throw runtime_error(format("{}:{}: '{}' {}", pos.line+1, pos.column+1, error.set_what(format("{}:{}: '{}' {}", pos.line+1, pos.column+1,
params[0], error.what())); params[0], error.what()));
throw;
} }
} }

View File

@ -2140,7 +2140,7 @@ const CommandDesc fail_cmd = {
CommandCompleter{}, CommandCompleter{},
[](const ParametersParser& parser, Context&, const ShellContext&) [](const ParametersParser& parser, Context&, const ShellContext&)
{ {
throw runtime_error(fix_atom_text(join(parser, ' ', false))); throw failure{fix_atom_text(join(parser, " "))};
} }
}; };

View File

@ -18,11 +18,17 @@ struct runtime_error : exception
: m_what(std::move(what)) {} : m_what(std::move(what)) {}
StringView what() const override { return m_what; } StringView what() const override { return m_what; }
void set_what(String what) { m_what = std::move(what); }
private: private:
String m_what; String m_what;
}; };
struct failure : runtime_error
{
using runtime_error::runtime_error;
};
struct logic_error : exception struct logic_error : exception
{ {
}; };