better error reporting on errors in js libraries; fixes #2033