Skip to content

Commit 2ea8a3e

Browse files
committed
safari: Surface helpful safaridriver error message to end-user
The safaridriver provides useful diagnostic and remedy advice in its error messages, so let's surface these by default by wrapping them in QTapError. This also means we trade a not-useful internal stack trace for more useful "Bail out from $testfile in $browser" attribution. Before: ``` $ bin/qtap.js -b safari tests/fixtures/pass.html __ERROR__ Error: Failed to create new session at safariOne (/qtap/src/safari.js:112:13) ``` After: ``` $ bin/qtap.js -b safari tests/fixtures/pass.html __ERROR__ Bail out from tests/fixtures/pass.html in Safari: Error: Could not create a session: You must enable 'Allow remote automation' in the Developer section of Safari Settings to control Safari via WebDriver. HTTP 500 session not created Failed to create a Safari session. ```
1 parent f8cc69f commit 2ea8a3e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/safari.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import which from 'which';
2-
import { LocalBrowser, CommandNotFoundError } from './util.js';
2+
import { LocalBrowser, QTapError, CommandNotFoundError } from './util.js';
33
/** @import { Logger } from './qtap.js' */
44

55
async function delay (wait) {
@@ -83,7 +83,7 @@ async function safariOne (url, signals, logger) {
8383
/** @type {any} */
8484
const data = await resp.json();
8585
if (!resp.ok) {
86-
throw `HTTP ${resp.status} ${data?.value?.error}, ${data?.value?.message || ''}`;
86+
throw `${data?.value?.message || ''}\nHTTP ${resp.status} ${data?.value?.error}`;
8787
}
8888
return data.value;
8989
}
@@ -109,7 +109,7 @@ async function safariOne (url, signals, logger) {
109109
continue;
110110
}
111111
logger.warning('safaridriver_session_error', e);
112-
throw new Error('Failed to create new session');
112+
throw new QTapError((e.message || e) + '\nFailed to create a Safari session.');
113113
}
114114
}
115115

0 commit comments

Comments
 (0)