Esempio n. 1
0
def execute_element(
    executor: ControlledInstructionExecutor, element: SectionContentElement,
    instruction_info: InstructionInfo
) -> Optional[SingleInstructionExecutionFailure]:
    """
    :param element: Must be an instruction (i.e., element.is_instruction is True)
    :return: If None, then the execution was successful.
    """

    try:
        instruction = instruction_info.instruction
        assert isinstance(instruction,
                          TestCaseInstruction), _INSTRUCTION_TYPE_ERROR_MESSAGE
        fail_info = executor.apply(instruction)
        if fail_info is None:
            return None
        return SingleInstructionExecutionFailure(
            ExecutionFailureStatus(fail_info.status.value),
            element.source_location_info.source_location_path,
            FailureDetails.new_message(fail_info.error_message))
    except HardErrorException as ex:
        return SingleInstructionExecutionFailure(
            ExecutionFailureStatus.HARD_ERROR,
            element.source_location_info.source_location_path,
            FailureDetails.new_message(ex.error))
    except Exception as ex:
        from exactly_lib.util import traceback_
        return SingleInstructionExecutionFailure(
            ExecutionFailureStatus.INTERNAL_ERROR,
            element.source_location_info.source_location_path,
            FailureDetails.new_exception(ex, traceback_.traceback_as_str()))
Esempio n. 2
0
 def action():
     res = self._validation_executor.apply(self._action_to_check)
     if res is not None:
         raise PhaseStepFailureException(
             failure_con.apply(
                 ExecutionFailureStatus(res.status.value),
                 FailureDetails.new_message(res.error_message)))
Esempio n. 3
0
 def action():
     res = self.atc.validate_post_setup(self.environment_for_validate_post_setup)
     if not res.is_success:
         raise PhaseStepFailureException(
             failure_con(ExecutionFailureStatus(res.status.value),
                         FailureDetails.new_message(res.failure_message))
         )
Esempio n. 4
0
 def action():
     res = self._action_to_check.validate_pre_sds(self._instruction_environment_pre_sds)
     if not res.is_success:
         raise PhaseStepFailureException(
             failure_con.apply(ExecutionFailureStatus(res.status.value),
                               FailureDetails.new_message(res.failure_message))
         )
Esempio n. 5
0
 def action():
     mb_failure_message = self.atc_input.validate()
     if mb_failure_message:
         raise PhaseStepFailureException(
             failure_con(ExecutionFailureStatus.HARD_ERROR,
                         FailureDetails.new_message(mb_failure_message))
         )
Esempio n. 6
0
 def action():
     res = self.atc.prepare(self.environment_for_other_steps,
                            self.os_services)
     if not res.is_success:
         raise PhaseStepFailureException(
             failure_con(ExecutionFailureStatus.HARD_ERROR,
                         FailureDetails.new_message(res.failure_message))
         )
Esempio n. 7
0
def _raise_he__single_line(
    format_str: str,
    format_map: Mapping[str, ToStringObject],
    ex: Exception,
):
    raise HardErrorException(
        failure_details.FailureDetailsRenderer(
            FailureDetails.new_message(
                text_docs.single_line(
                    str_constructor.FormatMap(format_str, format_map)), ex)))
Esempio n. 8
0
 def parse_action() -> ActionToCheck:
     try:
         return actor.parse(self.instructions)
     except ParseException as ex:
         raise PhaseStepFailureException(
             failure_constructor.apply(
                 ExecutionFailureStatus.SYNTAX_ERROR,
                 FailureDetails.new_message(ex.cause)
             )
         )
Esempio n. 9
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     settings = atc_proc_exe_settings.for_atc(environment, atc_input)
     try:
         exit_code = self._executor.execute(environment, settings,
                                            atc_input.stdin, output)
         return eh.new_eh_exit_code(exit_code)
     except HardErrorException as ex:
         return eh.new_eh_hard_error(FailureDetails.new_message(ex.error))
Esempio n. 10
0
 def execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
     os_services: OsServices,
     atc_input: AtcExecutionInput,
     output: StdOutputFiles,
 ) -> ExitCodeOrHardError:
     resolving_environment = full_resolving_env_for_instruction_env(
         os_services, environment)
     try:
         command = self._make_command(resolving_environment)
         settings = atc_proc_exe_settings.for_atc(environment, atc_input)
         with std_files.of_optional_stdin(atc_input.stdin,
                                          output) as std_files_:
             exit_code = os_services.command_executor.execute(
                 command, settings, std_files_)
         return eh.new_eh_exit_code(exit_code)
     except HardErrorException as ex:
         return eh.new_eh_hard_error(FailureDetails.new_message(ex.error))
Esempio n. 11
0
 def hard_error(self, ex: HardErrorException) -> PhaseStepFailure:
     return self.apply(ExecutionFailureStatus.HARD_ERROR,
                       FailureDetails.new_message(ex.error))