Skip to content

Commit 0e65931

Browse files
umair-ablyclaude
andcommitted
DX-1205: split legacy import-shim throws into message + hint
Aligns with the DX-1204 / DX-1209 convention that ErrorInfo throws separate *what failed* (message) from *how to fix it* (hint). The shims still throw plain Error rather than ErrorInfo — pulling in ErrorInfo would mean require'ing the built bundle just to throw, which defeats the point of a top-level alias shim. - promises.js / callbacks.js: stamp .hint on the thrown Error. - Tests assert on err.message + err.hint separately (drift-pin against silent rephrasing). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4d23cde commit 0e65931

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

callbacks.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3-
throw new Error(
4-
"'ably/callbacks' was the v1 callback API entry point and is no longer available. ably-js v2 is promise-only — import from 'ably' directly and switch to await / .then(). See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md",
5-
);
3+
const err = new Error("'ably/callbacks' was the v1 callback API entry point and is no longer available.");
4+
err.hint =
5+
"ably-js v2 is promise-only — import from 'ably' directly and switch to await / .then(). See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md";
6+
throw err;

promises.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3-
throw new Error(
4-
"'ably/promises' was the v1 entry point. ably-js v2 is promise-only — import from 'ably' directly. See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md",
5-
);
3+
const err = new Error("'ably/promises' was the v1 entry point and is no longer available.");
4+
err.hint =
5+
"ably-js v2 is promise-only — import from 'ably' directly. See https://github.com/ably/ably-js/blob/main/docs/migration-guides/v2/lib.md";
6+
throw err;

test/unit/legacy-import-shims.test.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@ define(['chai'], function (chai) {
1313
require(abs);
1414
}
1515

16-
it("'ably/promises' shim throws naming the v1 entry point and migration guide", function () {
17-
expect(() => loadShim('promises.js'))
18-
.to.throw(Error)
19-
.with.property('message')
20-
.that.matches(/'ably\/promises' was the v1 entry point/)
21-
.and.matches(/migration-guides\/v2\/lib\.md/);
16+
it("'ably/promises' shim throws naming the v1 entry point, with a hint pointing at the migration guide", function () {
17+
let caught;
18+
try {
19+
loadShim('promises.js');
20+
} catch (err) {
21+
caught = err;
22+
}
23+
expect(caught).to.be.an.instanceOf(Error);
24+
expect(caught.message).to.match(/'ably\/promises' was the v1 entry point/);
25+
expect(caught.hint).to.be.a('string');
26+
expect(caught.hint).to.match(/promise-only/);
27+
expect(caught.hint).to.match(/migration-guides\/v2\/lib\.md/);
2228
});
2329

24-
it("'ably/callbacks' shim throws naming the v1 callback API and migration guide", function () {
25-
expect(() => loadShim('callbacks.js'))
26-
.to.throw(Error)
27-
.with.property('message')
28-
.that.matches(/'ably\/callbacks' was the v1 callback API entry point/)
29-
.and.matches(/migration-guides\/v2\/lib\.md/);
30+
it("'ably/callbacks' shim throws naming the v1 callback API, with a hint pointing at the migration guide", function () {
31+
let caught;
32+
try {
33+
loadShim('callbacks.js');
34+
} catch (err) {
35+
caught = err;
36+
}
37+
expect(caught).to.be.an.instanceOf(Error);
38+
expect(caught.message).to.match(/'ably\/callbacks' was the v1 callback API entry point/);
39+
expect(caught.hint).to.be.a('string');
40+
expect(caught.hint).to.match(/await/);
41+
expect(caught.hint).to.match(/migration-guides\/v2\/lib\.md/);
3042
});
3143

3244
it('package.json exports map wires the legacy subpaths to the shim files and their types', function () {

0 commit comments

Comments
 (0)