dequelabs / axe-webdriverjs

Provides a chainable axe API for Selenium's WebDriverJS and automatically injects into all frames.
Mozilla Public License 2.0
130 stars 46 forks source link

BREAKING CHANGE: Allow errors bubble up to the caller #79

Closed stephenmathieson closed 6 years ago

stephenmathieson commented 6 years ago

THIS IS A BREAKING CHANGE. This patch prevents unhandled Promise rejections from crashing the process by allowing the caller to handle them instead.

To properly call Builder#analyze(), you must change your code from:

builder.analyze(function(results) {
  // Do something with results
});

To:

builder.analyze(function(err, results) {
  if (err) {
    // handle error
  }

  // Do something with results
});

Additionally, when using the Promise returned by Builder#analyze(), you must add a .catch() block to handle the possible rejection. For example:

builder
  .analyze()
  .then(results => {
    // Do something with results
  })
  .catch(err => {
    // handle error
  });

NOTE: when using a Promise and a callback, the Promise will never be rejected. The callback will be provided the error instead. This ensures we don't require users to handle the same error twice.

Fixes #56.

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

WilcoFiers commented 6 years ago

Should look into how this impacts Attest as well @stephenmathieson

stephenmathieson commented 6 years ago

After discussing this with @WilcoFiers, we've decided #83 is a better (temporary) solution.