<commit_before>require 'sinatra'

POSSIBLE_TYPES = [
  NoMethodError, ActionController::RoutingError,
  TypeError, NameError, StandardError
]

MESSAGES = [
  "Could not find FooBar with ID = baz",
  "No route for /kakka",
  "can't convert Hash into String",
  "Invalid JSON string"
]

LOCATIONS = [
  "answer_forms_controller#show",
  "reports_controller#generror"
]

post '/api/projects/:api_key/fails' do
  begin
    project = Project.first
    data    = ActiveSupport::JSON.decode(params[:data])    
    Fail.create_or_combine_with_similar_fail(project, data)
    
    status 200
    "OK"
  rescue
    status 400
    "Bad Request"
  end
end

get '/api/projects/:api_key/fails/generate' do
  begin
    type = POSSIBLE_TYPES[rand(POSSIBLE_TYPES.size)]
    msg  = MESSAGES[rand(MESSAGES.size)]
    error = type.new(msg)
  
    raise error
  rescue => boom
    data = [
      [:summary, [
        [:type, boom.class.to_s, {:use_in_checksum => true}],
        [:message, boom.message, {:use_in_checksum => false}],
        [:location, LOCATIONS[rand(LOCATIONS.size)], {:use_in_checksum => false}],
        [:top_of_backtrace, boom.backtrace[0], {:use_in_checksum => false}]
      ]],
      [:info, [
        [:full_backtrace, boom.backtrace.join('\n'), {:use_in_checksum => false}],
        [:parameters, "{'hello' => 'moi'}", {:use_in_checksum => false}]
      ]]
    ]
    
    Fail.create_or_combine_with_similar_fail(Project.first,
      {:title => "#{boom.class}: #{boom.message}",
       :data => data})
  end
end<commit_msg>Find project to generate by ID<commit_after>require 'sinatra'

POSSIBLE_TYPES = [
  NoMethodError, ActionController::RoutingError,
  TypeError, NameError, StandardError
]

MESSAGES = [
  "Could not find FooBar with ID = baz",
  "No route for /kakka",
  "can't convert Hash into String",
  "Invalid JSON string"
]

LOCATIONS = [
  "answer_forms_controller#show",
  "reports_controller#generror"
]

post '/api/projects/:api_key/fails' do
  begin
    project = Project.first
    data    = ActiveSupport::JSON.decode(params[:data])    
    Fail.create_or_combine_with_similar_fail(project, data)
    
    status 200
    "OK"
  rescue
    status 400
    "Bad Request"
  end
end

get '/api/projects/:api_key/fails/generate' do
  begin
    type = POSSIBLE_TYPES[rand(POSSIBLE_TYPES.size)]
    msg  = MESSAGES[rand(MESSAGES.size)]
    error = type.new(msg)
  
    raise error
  rescue => boom
    data = [
      [:summary, [
        [:type, boom.class.to_s, {:use_in_checksum => true}],
        [:message, boom.message, {:use_in_checksum => false}],
        [:location, LOCATIONS[rand(LOCATIONS.size)], {:use_in_checksum => false}],
        [:top_of_backtrace, boom.backtrace[0], {:use_in_checksum => false}]
      ]],
      [:info, [
        [:full_backtrace, boom.backtrace.join('\n'), {:use_in_checksum => false}],
        [:parameters, "{'hello' => 'moi'}", {:use_in_checksum => false}]
      ]]
    ]
    
    project = Project.find(params[:api_key])
    p project
    Fail.create_or_combine_with_similar_fail(project,
      {:title => "#{boom.class}: #{boom.message}",
       :data => data})
  end
end
{'fraction_non_alphanumeric': 0.14641943734015345, 'fraction_numerical': 0.004475703324808184, 'mean_word_length': 3.292181069958848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1539799', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1095, 'n_words': 210}