Refactor and simplify error reporting for JS execution