Meteor.Error is caught by Selenium package and does not propagate to client


#1

This may be more of a Selenium question, but I thought I’d post it there to see if there is a Meteor-specific workaround.

My code, called on server from a method:

var webdriver = require('selenium-webdriver')

function getPage(page) {

    driver = driver || new webdriver.Builder().forBrowser('chrome').build();

    driver.get(page).catch(function(error){
        throw new Meteor.Error("Can't get page " + page)
    })
}

throwing a Meteor.Error trips Selenium’s error handler, resulting in restart of Node:

2:49:40.093(-7)? (STDERR) 
W20160712-12:49:40.104(-7)? (STDERR) /Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:654
W20160712-12:49:40.104(-7)? (STDERR)     throw error;
W20160712-12:49:40.105(-7)? (STDERR)     ^
W20160712-12:49:40.105(-7)? (STDERR) Error: [Can't get page i]
W20160712-12:49:40.118(-7)? (STDERR)     at imports/somethingSel.js:35:15
W20160712-12:49:40.120(-7)? (STDERR)     at ManagedPromise.invokeCallback_ (/Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:1379:14)
W20160712-12:49:40.121(-7)? (STDERR)     at TaskQueue.execute_ (/Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:2913:14)
W20160712-12:49:40.123(-7)? (STDERR)     at TaskQueue.executeNext_ (/Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:2896:21)
W20160712-12:49:40.124(-7)? (STDERR)     at /Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:2775:27
W20160712-12:49:40.132(-7)? (STDERR)     at /Users/irinaapex/irina/meteor/selenium/node_modules/selenium-webdriver/lib/promise.js:639:7
W20160712-12:49:40.134(-7)? (STDERR)     at /Users/irinaapex/.meteor/packages/promise/.0.8.3-beta.9.1fbal0n++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:32:39
=> Exited with code: 1
W20160712-12:49:53.217(-7)? (STDERR) Debugger listening on port 49906
=> Meteor server restarted

How do I fix this?


#2

Fom Selenium docs:

Bottom line: you must handle rejected promises.

So… it looks like Selenium won’t allow throwing a Meteor.Error from inside a promise chain. What would be the best workaround? Using the success callback for both success and error? Or is there an (undocumented?) way of transmitting an error to the client without throwing an exception?