How to use the appium-base-driver.errorFromCode function in appium-base-driver

To help you get started, we’ve selected a few appium-base-driver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appium / appium-android-driver / lib / bootstrap.js View on Github external
}
        log.debug('Received command result from bootstrap');
        try {
          streamData = JSON.parse(streamData + data);
          // we successfully parsed JSON so we've got all the data,
          // remove the socket listener and evaluate
          this.socketClient.removeAllListeners('data');
          if (streamData.status === 0) {
            return resolve(streamData.value);
          }
          reject(errorFromCode(streamData.status, streamData.value));
        } catch (err) {
          if (!_.isString(streamData)) {
            log.error('Got an unexpected error inside socket listener');
            log.error(err.stack);
            return reject(errorFromCode(13, err.message));
          }
          log.debug(`Stream still not complete, waiting up to ${SEND_COMMAND_TIMEOUT}ms for the data to arrive`);
          streamData += data;
          sendCommandTimeoutHandler = setTimeout(() => {
            const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
            log.error(errMsg);
            this.socketClient.removeAllListeners('data');
            reject(errorFromCode(13, errMsg));
          }, SEND_COMMAND_TIMEOUT);
        }
      });
    });
github appium / appium-android-driver / lib / bootstrap.js View on Github external
this.socketClient.on('data', (data) => {
        if (sendCommandTimeoutHandler) {
          clearTimeout(sendCommandTimeoutHandler);
        }
        log.debug('Received command result from bootstrap');
        try {
          streamData = JSON.parse(streamData + data);
          // we successfully parsed JSON so we've got all the data,
          // remove the socket listener and evaluate
          this.socketClient.removeAllListeners('data');
          if (streamData.status === 0) {
            return resolve(streamData.value);
          }
          reject(errorFromCode(streamData.status, streamData.value));
        } catch (err) {
          if (!_.isString(streamData)) {
            log.error('Got an unexpected error inside socket listener');
            log.error(err.stack);
            return reject(errorFromCode(13, err.message));
          }
          log.debug(`Stream still not complete, waiting up to ${SEND_COMMAND_TIMEOUT}ms for the data to arrive`);
          streamData += data;
          sendCommandTimeoutHandler = setTimeout(() => {
            const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
            log.error(errMsg);
            this.socketClient.removeAllListeners('data');
            reject(errorFromCode(13, errMsg));
          }, SEND_COMMAND_TIMEOUT);
        }
      });
github appium / appium-ios-driver / lib / uiauto / uiauto-client.js View on Github external
let cb = (result) => {
        // get back a JSONWP object, so decode and
        // just return the value
        if (result.status === 0) {
          resolve(result.value);
        } else if (result.status) {
          let jsonwpError = errorFromCode(result.status, result.value);
          reject(jsonwpError);
        } else {
          reject(new Error(result.value));
        }
      };
      this.commandQueue.push({cmd, cb});
github appium-boneyard / appium-android-bootstrap / lib / bootstrap.js View on Github external
this.socketClient.on('data', (data) => {
        if (sendCommandTimeoutHandler) {
          clearTimeout(sendCommandTimeoutHandler);
        }
        log.debug("Received command result from bootstrap");
        try {
          streamData = JSON.parse(streamData + data);
          // we successfully parsed JSON so we've got all the data,
          // remove the socket listener and evaluate
          this.socketClient.removeAllListeners('data');
          if (streamData.status === 0) {
            return resolve(streamData.value);
          }
          reject(errorFromCode(streamData.status, streamData.value));
        } catch (err) {
          if (!_.isString(streamData)) {
            log.error('Got an unexpected error inside socket listener');
            log.error(err.stack);
            return reject(errorFromCode(13, err.message));
          }
          log.debug(`Stream still not complete, waiting up to ${SEND_COMMAND_TIMEOUT}ms for the data to arrive`);
          streamData += data;
          sendCommandTimeoutHandler = setTimeout(() => {
            const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
            log.error(errMsg);
            this.socketClient.removeAllListeners('data');
            reject(errorFromCode(13, errMsg));
          }, SEND_COMMAND_TIMEOUT);
        }
      });
github appium-boneyard / appium-android-bootstrap / lib / bootstrap.js View on Github external
}
        log.debug("Received command result from bootstrap");
        try {
          streamData = JSON.parse(streamData + data);
          // we successfully parsed JSON so we've got all the data,
          // remove the socket listener and evaluate
          this.socketClient.removeAllListeners('data');
          if (streamData.status === 0) {
            return resolve(streamData.value);
          }
          reject(errorFromCode(streamData.status, streamData.value));
        } catch (err) {
          if (!_.isString(streamData)) {
            log.error('Got an unexpected error inside socket listener');
            log.error(err.stack);
            return reject(errorFromCode(13, err.message));
          }
          log.debug(`Stream still not complete, waiting up to ${SEND_COMMAND_TIMEOUT}ms for the data to arrive`);
          streamData += data;
          sendCommandTimeoutHandler = setTimeout(() => {
            const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
            log.error(errMsg);
            this.socketClient.removeAllListeners('data');
            reject(errorFromCode(13, errMsg));
          }, SEND_COMMAND_TIMEOUT);
        }
      });
    });
github Samsung / appium-tizen-driver / lib / tizen-bootstrap.js View on Github external
});
        this.socketClient.setTimeout(15000);
        this.socketClient.on('timeout', () => {
          this.socketClient.destroy();
          this.socketClient = null;
          this.isRestart = true;
          reject(errorFromCode(-1, "No response from Server"));
        });
        this.socketClient.on('end', () => {
          this.socketClient.destroy();
          this.socketClient = null;
          this.isRestart = true;
          reject(errorFromCode(-1, "Socket ended by Server"));
        });
      } catch (err) {
        reject(errorFromCode(-1, err));
      }
    });
  }
github Samsung / appium-tizen-driver / lib / tizen-bootstrap.js View on Github external
this.socketClient.on('end', () => {
          this.socketClient.destroy();
          this.socketClient = null;
          this.isRestart = true;
          reject(errorFromCode(-1, "Socket ended by Server"));
        });
      } catch (err) {
github Samsung / appium-tizen-driver / lib / tizen-bootstrap.js View on Github external
this.socketClient.on('data', (data) => {
          let streamData = '';
          log.debug(`Received command result from bootstrap : ${data}`);
          try {
            streamData = JSON.parse(streamData + data);
            this.socketClient.removeAllListeners('data');
            if (streamData.status === 0) {
              resolve(streamData.value);
            } else if (streamData.status === 44) {
              this.restartUIAutomator();
              resolve(false);
            }
            reject(errorFromCode(streamData.status));
          } catch (ign) {
            log.debug("Stream still not complete, waiting");
            streamData += data;
          }
        });
        this.socketClient.setTimeout(15000);
github appium / appium-android-driver / lib / bootstrap.js View on Github external
sendCommandTimeoutHandler = setTimeout(() => {
            const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
            log.error(errMsg);
            this.socketClient.removeAllListeners('data');
            reject(errorFromCode(13, errMsg));
          }, SEND_COMMAND_TIMEOUT);
        }
github appium-boneyard / appium-android-bootstrap / lib / bootstrap.js View on Github external
sendCommandTimeoutHandler = setTimeout(() => {
            const errMsg = `Server socket stopped responding. The recent response was '${streamData}'`;
            log.error(errMsg);
            this.socketClient.removeAllListeners('data');
            reject(errorFromCode(13, errMsg));
          }, SEND_COMMAND_TIMEOUT);
        }