调试在 Google App Engine 上部署时出现错误的 Google Web Toolkit 应用程序
我有一个 Google Web Toolkit 应用程序,正在部署到 Google App Engine。在已部署的应用程序中,我收到 JavaScript 错误 Uncaught TypeError: Cannot read property 'f' of null
。这听起来像是 Java NullPointerException 的 JavaScript 等价物。
问题是 GWT JavaScript 被混淆了,因此无法在浏览器中进行调试,并且我无法在可以使用 Java 调试器的托管模式下重现相同的问题。我认为我只在已部署的应用程序上看到错误的原因是我在 GAE 服务器上使用的数据库触发的内容与我在测试和开发期间使用的测试数据库不同。
那么,关于最佳的继续方式有什么想法吗?我考虑过以下事项:
- 部署我的应用程序的非混淆版本。尽管进行了大量的谷歌搜索,我还是不知道如何使用 Google Eclipse 插件提供的自动部署脚本来做到这一点。有谁知道吗?
- 下载我的 GAE 数据并将其复制到本地服务器
- 不知何故,我的开发代码使用 GAE 服务器而不是本地测试数据库来获取数据。这似乎是最好的主意...
任何人都可以建议如何继续这里吗?
最后,有没有办法在生产服务器上捕获这些 JavaScript 错误并将其记录在某处?如果没有日志记录,我将无法知道我的用户是否遇到服务器上未发生的错误。 GWT.log() 函数会自动从生产代码中删除...
I have a Google Web Toolkit application that I am deploying to Google App Engine. In the deployed application, I am getting a JavaScript error Uncaught TypeError: Cannot read property 'f' of null
. This sounds like the JavaScript equivalent of a Java NullPointerException.
The problem is that the GWT JavaScript is obfuscated, so it's impossible to debug in the browser and I can't reproduce the same problem in hosted mode where I could use the Java debugger. I think the reason I'm only seeing the error on the deployed application is that the database I'm using on the GAE server is triggering something differently than the test database I'm using during testing and development.
So, any ideas about the best way to proceed? I've thought of the following things:
- Deploy a non-obsfucated version of my application. Despite a lot of Googling, I can't figure out how to do this using the automatic deploy script provided with the Google Eclipse Plugin. Does anyone know?
- Download and copy my GAE data to the local server
- Somehow point my development code to use the GAE server for data instead of the local test database. This seems like the best idea...
Can anyone suggest how to proceed here?
Finally, is there a way to catch these JavaScript errors on the production server and log them somewhere? Without logging, I won't have anyway to know if my users are having errors that don't occur on the server. The GWT.log() function is automatically stripped out of the production code...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 如果您可以在本地复制 GAE 数据库所需的状态,则在本地计算机上运行 javascript 编译版本。这几乎肯定会产生相同的错误,但比完整的 AppEngine 部署要便宜得多。为此,请使用 GWT 编译器编译您的应用程序,然后正常启动它,然后将浏览器指向不带
?gwt.codesvr=127.0.0.1:9997
部分的指定地址。2) 将
-style PRETTY
或-style DETAILED
与 GWT 编译器一起使用以获得更好的 JavaScript。如果您使用此标志在本地编译一次,则部署到 AppEngine(使用 Eclipse 插件)将发送相同的非混淆版本。3) 检测您的代码(
Window.alert()
工作正常)以准确找出错误发生的位置。这对于查找 javascript 执行偏离托管模式执行的位置特别有用。4) 仅保留一种排列,加快编译过程。看看如何做到这一点:
如何加速 gwt 编译器?
5) Javascript在开发版本或单元测试中没有出现的错误(几乎总是)是由于 GWT 中的错误造成的,在您进行了一些调查之后,请访问 GWT 论坛或问题跟踪器,看看它是否是一个已知的错误以及是否有解决方法。
1) If you can replicate the needed state of your GAE database locally, then run the javascript compiled version on your local machine. This will almost certainly give the same error, but is a lot less expensive than a full AppEngine deployment. Do this by compiling your app with the GWT compiler, then start it normally, then point your browser to the specified address without the
?gwt.codesvr=127.0.0.1:9997
part.2) Use the
-style PRETTY
or-style DETAILED
with the GWT compiler to get nicer javascript. If you compile locally with this flag once, then deploying to AppEngine (with the Eclipse plugin) will send the same non-obfuscated version.3) Instrument your code (
Window.alert()
works fine) to figure out exactly where the error happens. This is especially useful to find where the javascript execution deviates from the hosted mode execution.4) Speed-up your compilation process by keeping only one permutation. See how to do this there:
How do I speed up the gwt compiler?
5) Javascript errors that don't show up in the development version or in unit tests are (almost always) due to a bug in GWT, after you've investigated a little, drop by the GWT forum or issue tracker and see if it's a known bug and whether or not there is a workaround.