diff --git a/package.json b/package.json index 2ddb699..d35eff0 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "test:flow": "flow check", "test:tcp": "tape-ext test/TCPSocket", "test:api": "tape-ext test/API", + "test:dns-sd": "tape-ext test/ServiceDiscovery", "precommit": "lint-staged", "demo": "cross-env MOZ_DISABLE_CONTENT_SANDBOX=1 web-ext run --firefox=nightly --browser-console --url about:debugging", "demo:discovery": "cross-env MOZ_DISABLE_CONTENT_SANDBOX=1 web-ext run --firefox=nightly --browser-console --url about:debugging --source-dir demo/discovery", diff --git a/src/ServiceDiscovery/client.js b/src/ServiceDiscovery/client.js index bf6bd6f..1597c6f 100644 --- a/src/ServiceDiscovery/client.js +++ b/src/ServiceDiscovery/client.js @@ -96,7 +96,9 @@ interface Host { } } - const notFound = new ExtensionError("Host for the object not found") + const notFound = new context.cloneScope.RangeError( + "Host for the object not found" + ) let notFoundPromiseCache = null const notFoundPromise = () => { @@ -159,7 +161,7 @@ interface Host { resolve(service) } catch (error) { - reject(new ExtensionError(error)) + reject(new cloneScope.Error(error.message)) } }) } @@ -280,14 +282,14 @@ interface Host { switch (message.type) { case "onStopDiscoveryFailed": { return this.throw( - new ExtensionError( + new context.cloneScope.Error( `Failed to stop discovery ${message.errorCode}` ) ) } case "onStartDiscoveryFailed": { return this.throw( - new ExtensionError( + new context.cloneScope.Error( `Failed to start discovery ${message.errorCode}` ) ) diff --git a/test/ServiceDiscovery/test.js b/test/ServiceDiscovery/test.js index 945acf9..c4e804a 100644 --- a/test/ServiceDiscovery/test.js +++ b/test/ServiceDiscovery/test.js @@ -232,3 +232,19 @@ test("discovery with attributes", async test => { await announcement await discovery }) + +test("unwrappable exceptions #67", async test => { + try { + const service = await browser.ServiceDiscovery.announce({ + name: "error", + type: "boom", + protocol: "crash" + }) + test.fail(`Exception was expected on wrong protocol`) + } catch (error) { + test.ok( + error.message.includes(`must be either "udp" or "tcp"`), + "error is unwrappable" + ) + } +})