<commit_before>module DTK; class ConfigAgent; module Adapter
  class DtkProvider
    module InterpretResults
      module Mixin
        def action_results(result,action)
          data = data_field_in_results(result)
          unless data.kind_of?(Hash)
            Log.error_pp(["Unexpected that data field is not a hash:",data])
            return nil
          end
          data[:results]
        end
        
        def errors_in_result?(result,action)
          # TODO: action passed in so can look to see at 'action action_status interpretation"
          default_errors_action_status?(result)
        end
        
        def interpret_error(error_in_result,components)
          error_in_result
        end

       private
        def default_errors_action_status?(results)
          if results_data = results[:results]
            # only last one can be failure
            last_results = (results_data.kind_of?(Array) ? results_data.last : results_data)
            status = last_results['status']
            if status and last_results['status'].to_s != '0'
              stderr = last_results['stderr']||''
              err_msg = (stderr.empty? ? "Error in action; syscall status = #{status.to_s}" : stderr)
              [err_msg]                
            end
          end
        end

        def data_field_in_results(result)
          # TODO: will be deprecating the [:data][:data] form
          (result[:data]||{})[:data]||result[:data]||{}
        end
<commit_msg>Small fix for taking into the account all action commands that return with nonzero exit status<commit_after>module DTK; class ConfigAgent; module Adapter
  class DtkProvider
    module InterpretResults
      module Mixin
        def action_results(result,action)
          data = data_field_in_results(result)
          unless data.kind_of?(Hash)
            Log.error_pp(["Unexpected that data field is not a hash:",data])
            return nil
          end
          data[:results]
        end
        
        def errors_in_result?(result,action)
          # TODO: action passed in so can look to see at 'action action_status interpretation"
          default_errors_action_status?(result)
        end
        
        def interpret_error(error_in_result,components)
          error_in_result
        end

       private
        def default_errors_action_status?(results)
          if results_data = results[:results]
            if results_data.kind_of?(Array)
              err_msgs = []
              results_data.each do |result|
                status = result['status']
                if status and result['status'].to_s != '0'
                  stderr = result['stderr']||''
                  err_msgs << (stderr.empty? ? "Error in action; syscall status = #{status.to_s}" : stderr)
                end
              end
              err_msgs unless err_msgs.empty?
            else
              status = results_data['status']
              if status and results_data['status'].to_s != '0'
                stderr = results_data['stderr']||''
                err_msg = (stderr.empty? ? "Error in action; syscall status = #{status.to_s}" : stderr)
                [err_msg]                
              end
            end
          end

        end

        def data_field_in_results(result)
          # TODO: will be deprecating the [:data][:data] form
          (result[:data]||{})[:data]||result[:data]||{}
        end

{'fraction_non_alphanumeric': 0.08751458576429405, 'fraction_numerical': 0.0008751458576429405, 'mean_word_length': 1.859883236030025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4741464', 'n_tokens_mistral': 912, 'n_tokens_neox': 894, 'n_words': 238}