Removed Code duplication and fixed the indentation

1. The same code was duplicated in all the catch block. So Created a
private method emitErrorTuple to encapsulate the logic.
2. Removed unnecessary spaces
3. Prefixed the error_line and error_string map keys with underscore to
avoid conflict with actual keys of json.
4. Fixed the test case accordingly