|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// (all errors which are visible to the runner script made by the user under normal conditions) |
| 4 | + |
| 5 | +/** |
| 6 | + * An argument passed to one of the api functions or setters is incompatible with the type expected by that function |
| 7 | + */ |
| 8 | +const ILLEGAL_ARGUMENT_ERROR = 'Openrunner:IllegalArgumentError'; |
| 9 | + |
| 10 | +/** |
| 11 | + * An api function has been called at an inappropriate time |
| 12 | + */ |
| 13 | +const ILLEGAL_STATE_ERROR = 'Openrunner:IllegalStateError'; |
| 14 | + |
| 15 | +/** |
| 16 | + * Unable to navigate to the specified URL using tab.navigate() |
| 17 | + */ |
| 18 | +const NAVIGATE_ERROR = 'Openrunner:NavigateError'; |
| 19 | + |
| 20 | +/** |
| 21 | + * And assertion made by the script has failed. |
| 22 | + */ |
| 23 | +const ASSERTION_ERROR = 'Openrunner:AssertionError'; |
| 24 | + |
| 25 | +/** |
| 26 | + * The script is waiting for a condition in the DOM (e.g. a specific DOM Element to be present) which has been |
| 27 | + * aborted because it took too long. |
| 28 | + */ |
| 29 | +const DOM_WAIT_TIMEOUT_ERROR = 'BluefoxTimeoutError'; |
| 30 | + |
| 31 | +/** |
| 32 | + * The script is waiting for a new page to be navigated too, which has been aborted because it took too long. |
| 33 | + */ |
| 34 | +const NEW_PAGE_WAIT_TIMEOUT_ERROR = 'Openrunner:NewPageWaitTimeoutError'; |
| 35 | + |
| 36 | + |
| 37 | +/** |
| 38 | + * An active transaction has been aborted because the script is stopping. |
| 39 | + */ |
| 40 | +const TRANSACTION_ABORTED_ERROR = 'Openrunner:TransactionAbortedError'; |
| 41 | + |
| 42 | +/** |
| 43 | + * An active content script (e.g. `tab.run()`)has been aborted because the page is navigating away, |
| 44 | + * the tab is closing, or the script is stopping. |
| 45 | + */ |
| 46 | + |
| 47 | +const CONTENT_SCRIPT_ABORTED_ERROR = 'Openrunner:ContentScriptAbortedError'; |
| 48 | + |
| 49 | +/** |
| 50 | + * The Openrunner script has been running longer than its configured timeout limit and has been aborted. |
| 51 | + * For example: |
| 52 | + * 'Openrunner-Script-Timeout: 10s' |
| 53 | + */ |
| 54 | +const SCRIPT_EXECUTION_TIMEOUT_ERROR = 'Openrunner:ScriptExecutionTimeoutError'; |
| 55 | + |
| 56 | +const createErrorShorthand = name => (message, cause = null) => { |
| 57 | + const err = new Error(message); |
| 58 | + err.name = name; |
| 59 | + err.cause = cause; |
| 60 | + return err; |
| 61 | +}; |
| 62 | + |
| 63 | +const translateRpcErrorName = err => { |
| 64 | + const match = /RPCRequestError<(Openrunner:.*?)>/.exec(err && err.name); |
| 65 | + if (match) { |
| 66 | + err.name = match[1]; |
| 67 | + } |
| 68 | + throw err; |
| 69 | +}; |
| 70 | + |
| 71 | +module.exports = { |
| 72 | + ILLEGAL_ARGUMENT_ERROR, |
| 73 | + ILLEGAL_STATE_ERROR, |
| 74 | + NAVIGATE_ERROR, |
| 75 | + ASSERTION_ERROR, |
| 76 | + DOM_WAIT_TIMEOUT_ERROR, |
| 77 | + NEW_PAGE_WAIT_TIMEOUT_ERROR, |
| 78 | + TRANSACTION_ABORTED_ERROR, |
| 79 | + CONTENT_SCRIPT_ABORTED_ERROR, |
| 80 | + SCRIPT_EXECUTION_TIMEOUT_ERROR, |
| 81 | + illegalArgumentError: createErrorShorthand(ILLEGAL_ARGUMENT_ERROR), |
| 82 | + illegalStateError: createErrorShorthand(ILLEGAL_STATE_ERROR), |
| 83 | + navigateError: createErrorShorthand(NAVIGATE_ERROR), |
| 84 | + assertionError: createErrorShorthand(ASSERTION_ERROR), |
| 85 | + newPageWaitTimeoutError: createErrorShorthand(NEW_PAGE_WAIT_TIMEOUT_ERROR), |
| 86 | + transactionAbortedError: createErrorShorthand(TRANSACTION_ABORTED_ERROR), |
| 87 | + contentScriptAbortedError: createErrorShorthand(CONTENT_SCRIPT_ABORTED_ERROR), |
| 88 | + scriptExecutionTimeoutError: createErrorShorthand(SCRIPT_EXECUTION_TIMEOUT_ERROR), |
| 89 | + translateRpcErrorName, |
| 90 | +}; |
0 commit comments