forked from OSchip/llvm-project
[CommandInterpreter] Early return on error (NFC)
We save two levels of indentation by returning early if the given file doesn't exists or cannot be opened. llvm-svn: 353472
This commit is contained in:
parent
96f54de8ff
commit
166c262f23
|
@ -2364,13 +2364,27 @@ enum {
|
|||
void CommandInterpreter::HandleCommandsFromFile(
|
||||
FileSpec &cmd_file, ExecutionContext *context,
|
||||
CommandInterpreterRunOptions &options, CommandReturnObject &result) {
|
||||
if (FileSystem::Instance().Exists(cmd_file)) {
|
||||
StreamFileSP input_file_sp(new StreamFile());
|
||||
if (!FileSystem::Instance().Exists(cmd_file)) {
|
||||
result.AppendErrorWithFormat(
|
||||
"Error reading commands from file %s - file not found.\n",
|
||||
cmd_file.GetFilename().AsCString("<Unknown>"));
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
StreamFileSP input_file_sp(new StreamFile());
|
||||
std::string cmd_file_path = cmd_file.GetPath();
|
||||
Status error = FileSystem::Instance().Open(input_file_sp->GetFile(),
|
||||
cmd_file, File::eOpenOptionRead);
|
||||
if (error.Success()) {
|
||||
Status error = FileSystem::Instance().Open(input_file_sp->GetFile(), cmd_file,
|
||||
File::eOpenOptionRead);
|
||||
|
||||
if (error.Fail()) {
|
||||
result.AppendErrorWithFormat(
|
||||
"error: an error occurred read file '%s': %s\n", cmd_file_path.c_str(),
|
||||
error.AsCString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
Debugger &debugger = GetDebugger();
|
||||
|
||||
uint32_t flags = 0;
|
||||
|
@ -2391,8 +2405,7 @@ void CommandInterpreter::HandleCommandsFromFile(
|
|||
if (m_command_source_flags.empty()) {
|
||||
if (GetStopCmdSourceOnError())
|
||||
flags |= eHandleCommandFlagStopOnError;
|
||||
} else if (m_command_source_flags.back() &
|
||||
eHandleCommandFlagStopOnError) {
|
||||
} else if (m_command_source_flags.back() & eHandleCommandFlagStopOnError) {
|
||||
flags |= eHandleCommandFlagStopOnError;
|
||||
}
|
||||
} else if (options.m_stop_on_error == eLazyBoolYes) {
|
||||
|
@ -2404,8 +2417,7 @@ void CommandInterpreter::HandleCommandsFromFile(
|
|||
if (options.GetStopOnCrash()) {
|
||||
if (m_command_source_flags.empty()) {
|
||||
flags |= eHandleCommandFlagStopOnCrash;
|
||||
} else if (m_command_source_flags.back() &
|
||||
eHandleCommandFlagStopOnCrash) {
|
||||
} else if (m_command_source_flags.back() & eHandleCommandFlagStopOnCrash) {
|
||||
flags |= eHandleCommandFlagStopOnCrash;
|
||||
}
|
||||
}
|
||||
|
@ -2414,8 +2426,7 @@ void CommandInterpreter::HandleCommandsFromFile(
|
|||
if (m_command_source_flags.empty()) {
|
||||
// Echo command by default
|
||||
flags |= eHandleCommandFlagEchoCommand;
|
||||
} else if (m_command_source_flags.back() &
|
||||
eHandleCommandFlagEchoCommand) {
|
||||
} else if (m_command_source_flags.back() & eHandleCommandFlagEchoCommand) {
|
||||
flags |= eHandleCommandFlagEchoCommand;
|
||||
}
|
||||
} else if (options.m_echo_commands == eLazyBoolYes) {
|
||||
|
@ -2439,8 +2450,7 @@ void CommandInterpreter::HandleCommandsFromFile(
|
|||
if (m_command_source_flags.empty()) {
|
||||
// Print output by default
|
||||
flags |= eHandleCommandFlagPrintResult;
|
||||
} else if (m_command_source_flags.back() &
|
||||
eHandleCommandFlagPrintResult) {
|
||||
} else if (m_command_source_flags.back() & eHandleCommandFlagPrintResult) {
|
||||
flags |= eHandleCommandFlagPrintResult;
|
||||
}
|
||||
} else if (options.m_print_results == eLazyBoolYes) {
|
||||
|
@ -2482,20 +2492,6 @@ void CommandInterpreter::HandleCommandsFromFile(
|
|||
m_command_source_depth--;
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
debugger.SetAsyncExecution(old_async_execution);
|
||||
} else {
|
||||
result.AppendErrorWithFormat(
|
||||
"error: an error occurred read file '%s': %s\n",
|
||||
cmd_file_path.c_str(), error.AsCString());
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
}
|
||||
|
||||
} else {
|
||||
result.AppendErrorWithFormat(
|
||||
"Error reading commands from file %s - file not found.\n",
|
||||
cmd_file.GetFilename().AsCString("<Unknown>"));
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ScriptInterpreter *CommandInterpreter::GetScriptInterpreter(bool can_create) {
|
||||
|
|
Loading…
Reference in New Issue