Skip to content

Commit

Permalink
fix: improve error message for invalid server url (#1113)
Browse files Browse the repository at this point in the history
* feat: improve error message for invalid server url

* fix: further improve invalid server url messages
  • Loading branch information
eglitise committed Sep 29, 2023
1 parent 6d2540e commit 9e09a1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/renderer/actions/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export function applyClientMethod (params) {
} catch (error) {
console.log(error); // eslint-disable-line no-console
let methodName = params.methodName === 'click' ? 'tap' : params.methodName;
showError(error, methodName, 10);
showError(error, {methodName, secs: 10});
dispatch({type: METHOD_CALL_DONE});
}
};
Expand Down Expand Up @@ -282,7 +282,7 @@ export function quitSession (reason, killedByUser = true) {
await applyAction(dispatch, getState);
dispatch({type: QUIT_SESSION_DONE});
if (!killedByUser) {
showError(new Error(reason || i18n.t('Session has been terminated')), null, 0);
showError(new Error(reason || i18n.t('Session has been terminated')), {secs: 0});
}
};
}
Expand Down Expand Up @@ -408,7 +408,7 @@ export function searchForElement (strategy, selector) {
dispatch({type: SEARCHING_FOR_ELEMENTS_COMPLETED, elements, executionTime});
} catch (error) {
dispatch({type: SEARCHING_FOR_ELEMENTS_COMPLETED});
showError(error, 10);
showError(error, {methodName: 10});
}
};
}
Expand All @@ -434,7 +434,7 @@ export function getFindElementsTimes (findDataSource) {
});
} catch (error) {
dispatch({type: GET_FIND_ELEMENTS_TIMES_COMPLETED});
showError(error, 10);
showError(error, {methodName: 10});
}
};
}
Expand Down Expand Up @@ -564,7 +564,7 @@ export function selectLocatedElement (source, bounds, id) {
const action = selectElement(foundPath);
await action(dispatch, getState);
} else {
showError(new Error(i18n.t('findingElementInSourceFailed')), null, 8);
showError(new Error(i18n.t('findingElementInSourceFailed')), {secs: 8});
}
dispatch({type: FINDING_ELEMENT_IN_SOURCE_COMPLETED});
};
Expand Down
16 changes: 11 additions & 5 deletions app/renderer/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export function getCapsObject (caps) {
})));
}

export function showError (e, methodName = null, secs = 5) {
export function showError (e, params = { methodName: null, secs: 5, url: null }) {
const { secs, url } = params;
let { methodName } = params;
let errMessage;
if (e['jsonwire-error'] && e['jsonwire-error'].status === 7) {
// FIXME: we probably should set 'findElement' as the method name
Expand Down Expand Up @@ -148,8 +150,10 @@ export function showError (e, methodName = null, secs = 5) {
} else {
errMessage = i18n.t('Could not start session');
}
if (errMessage === 'ECONNREFUSED' || includes(errMessage, 'Failed to fetch')) {
errMessage = i18n.t('couldNotConnect');
if (errMessage === 'ECONNREFUSED' ||
includes(errMessage, 'Failed to fetch') ||
includes(errMessage, 'The requested resource could not be found')) {
errMessage = i18n.t('couldNotConnect', {url});
}

console.error(errMessage); // eslint-disable-line no-console
Expand Down Expand Up @@ -517,7 +521,9 @@ export function newSession (caps, attachSessId = null) {
driver = await Web2Driver.remote(serverOpts, desiredCapabilities);
}
} catch (err) {
showError(err, null, 0);
const { protocol, hostname, port, path } = serverOpts;
const url = `${protocol}://${hostname}:${port}${path}`;
showError(err, {secs: 0, url});
return false;
} finally {
dispatch({type: NEW_SESSION_DONE});
Expand Down Expand Up @@ -1050,7 +1056,7 @@ export function initFromQueryString (loadNewSession) {
const state = JSON.parse(initialState);
dispatch({type: SET_STATE_FROM_URL, state});
} catch (e) {
showError(new Error('Could not parse initial state from URL'), null, 0);
showError(new Error('Could not parse initial state from URL'), {secs: 0});
}
}

Expand Down
2 changes: 1 addition & 1 deletion assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"frameworkNotSupported": "Framework '{{framework}}' not supported",
"findElementFailure": "Failed to find element for '{{methodName}}'. Please refresh page and try again.",
"Could not start session": "Could not start session",
"couldNotConnect": "Could not connect to server; are you sure it's running? If you are using the browser version, also ensure your Appium server has been started with --allow-cors.",
"couldNotConnect": "Could not connect to Appium server URL '{{url}}'. Please check if the server is running and the URL is correct (valid URLs can be found at the start of the Appium server log). If you are using the Inspector's browser version, ensure the server has been started with '--allow-cors'.",
"Invalid URL:": "Invalid URL:",
"sauceCredentialsRequired": "Sauce username and access key are required!",
"testingbotCredentialsRequired": "TestingBot key and secret are required!",
Expand Down

0 comments on commit 9e09a1b

Please sign in to comment.