CodeCorrect

Inspiration

Developers sometimes spend a significant amount of time searching StackOverflow to find a fix for a code error that turned out to be a relatively simple (and solvable) problem. Why not automate that search process to find the optimal solution, and have it implemented within the code without any human intervention?

What it does

Including a small JavaScript file in your web code to override the window.onerror browser function will reroute uncaught exceptions to a locally running node.js web server. From there, a GET request is made to StackOverflow's API to search for questions (sorted by highest vote count) where the error message exists in the question title. The answers to each question are then extracted, and if answer content can be converted to instructions including where to make changes to the code, those changes will be made.

How I built it

I used JavaScript, with node.js running on the backend with the Express web server, and a custom function to override the browser's default window.onerror in order to make the GET request. I utilized Node's fs module to edit files on the computer.

Challenges I ran into

Making the request to StackOverflow's API endpoint proved to be difficult. In the browser and from Postman the result was a perfectly fine JSON object containing relevant questions and their URLs. But from node.js when printing the response body I got output that looked like this: http://i.imgur.com/FrC6bdH.png
Hinal from the Clarifai booth was a lifesaver in helping me figure out how to fix that. It turns out all I needed to do was include gzip: true, as part of the request headers.

Accomplishments that I'm proud of

I'm proud of not attempting to incorporate any of the sponsor companies' APIs just to be eligible for their prizes, because that would have caused unnecessary complexity and distracted me from achieving the main goal.

What I learned

I learned how to accept http requests from web pages that are being accessed from file:// origins, so that there is no need to serve it over localhost.

What's next for CodeCorrect

Expand the scope of errors for which it can find and implement appropriate solutions. This can be done by making extensions/integrations for popular IDEs, and searching other sites in addition to StackOverflow.