Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

PIVOTAL LABS
Standup 09-23-2010: ActiveRecord, Cucumber, and JS error info

Ask for Help

“Rails 3 / mysql2 gem: Errors from ActiveRecord due to DB handler going bad while running Cucumber tests. What to do?”

Cucumber does some forking, which may result in your connection being shared in multiple processes, which in turn results in Bad Things©. There may be a way to disable this behavior in the Cucumber rake task. A blunter, less desirable solution may be changing ActiveRecord to reconnect more frequently.

“How do I get HopToad-like errors back from my client-side Javascript?”

Put an error handler on document. You could make an AJAX request back to your server from there to send debugging information. Alternatively, making an AJAX request at the time of your error may not be safe, so you can also put a request in the source tag of an image or script tag, and this may be more reliable.

Comments
  1. Joseph Palermo says:

    So the Cucumber forking turned out to be us starting Solr for our cucumber tests using Sunspot. We would get errors about the MySQL connection being closed.

    The solution was simply to call ActiveRecord::Base.connection.reconnect! after we had started Solr.

  2. Peter Jaros says:

    Re: JS error handling:

    I don’t think it’s that simple. I just ran a test with the following code in Chrome, FF, and Safari:

    // Test 1:
    // window.onerror = function(arg1, arg2, arg3, arg4) {window.alert(“window.onerror: ” + JSON.stringify(arg1) + “, ” + JSON.stringify(arg2) + “, ” + JSON.stringify(arg3) + “, ” + JSON.stringify(arg4))};

    // Test 2:
    document.onerror = function(arg1, arg2, arg3, arg4) {document.alert(“document.onerror: ” + JSON.stringify(arg1) + “, ” + JSON.stringify(arg2) + “, ” + JSON.stringify(arg3) + “, ” + JSON.stringify(arg4))};

    // Test 3:
    // try {
    var foo = undefined.bar;
    // } catch(e) {
    // window.alert(“try/catch: ” + JSON.stringify(e))
    // }

    I uncommented each test and ran it in each browser. `document.onerror` was completely ignored. `window.onerror` was called in FF, and given three arguments: the message, the file, and the line number. Chrome and Safari ignored `window.onerror`. `try`/`catch` was supported in all three, of course, but it’s notoriously difficult to wrap every piece of code that needs it.

    I don’t have any other browsers handy, but if these three can’t agree, I think we’re screwed. If someone there came up with something that really does work across browsers, I will *gladly* take them to lunch for their efforts. :)

    (Disclaimer: Offer does not include airfare.)

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *