module Dependabot::SharedHelpers

def self.handle_json_parse_error(stdout, stderr, error_context, error_class)

def self.handle_json_parse_error(stdout, stderr, error_context, error_class)
  # If the JSON is invalid, the helper has likely failed
  # We should raise a more helpful error message
  message = if !stdout.strip.empty?
              stdout
            elsif !stderr.strip.empty?
              stderr
            else
              "No output from command"
            end
  error_class.new(
    message: message,
    error_class: "JSON::ParserError",
    error_context: error_context
  )
end