Skip to content

Commit a5369d5

Browse files
committed
Provide a useful message when switching versions from a function and the function does not exist in the target version
1 parent dc67f63 commit a5369d5

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

app/routes/project-version/functions/function.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class FunctionRoute extends Route {
1717
return model?.fn?.name;
1818
}
1919

20-
async model(params) {
20+
async model(params, transition) {
2121
const pVParams = this.paramsFor('project-version');
2222
const { project, project_version: compactVersion } = pVParams;
2323

@@ -38,10 +38,24 @@ export default class FunctionRoute extends Route {
3838
`${project}-${projectVersion}-${className}`.toLowerCase(),
3939
);
4040
} catch (e) {
41-
fnModule = await this.store.find(
42-
'namespace',
43-
`${project}-${projectVersion}-${className}`.toLowerCase(),
44-
);
41+
try {
42+
fnModule = await this.store.find(
43+
'namespace',
44+
`${project}-${projectVersion}-${className}`.toLowerCase(),
45+
);
46+
} catch (e2) {
47+
if (transition.to.name === transition?.from?.name) {
48+
let error = new Error(
49+
`We could not find function ${className}/${functionName} in v${compactVersion} of ${project}.`,
50+
);
51+
error.status = 404;
52+
error.attemptedProject = project;
53+
error.attemptedVersion = compactVersion;
54+
throw error;
55+
} else {
56+
throw e2;
57+
}
58+
}
4559
}
4660

4761
return {

tests/acceptance/switch-versions-test.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ async function waitForSettled() {
1111
await settled();
1212
}
1313

14+
const versionIndexLinkSelector = '[data-test-version-index-link]';
15+
1416
module('Acceptance | version navigation', function (hooks) {
1517
setupApplicationTest(hooks);
1618

@@ -312,8 +314,7 @@ module('Acceptance | version navigation', function (hooks) {
312314
);
313315
});
314316

315-
test('switching to a version that is missing a module or class offers a link to the API index for that version', async function (assert) {
316-
const versionIndexLinkSelector = '[data-test-version-index-link]';
317+
test('switching to a version that is missing a module offers a link to the API index for that version', async function (assert) {
317318
await visit('/ember/6.4/modules/@glimmer%2Ftracking%2Fprimitives%2Fcache');
318319
assert.strictEqual(
319320
currentURL(),
@@ -332,7 +333,9 @@ module('Acceptance | version navigation', function (hooks) {
332333
.dom(versionIndexLinkSelector)
333334
.includesText('v3.10')
334335
.hasAttribute('href', '/ember/3.10');
336+
});
335337

338+
test('switching to a version that is missing a class offers a link to the API index for that version', async function (assert) {
336339
await visit('/ember/3.0/classes/Ember.Debug');
337340
assert.strictEqual(currentURL(), '/ember/3.0/classes/Ember.Debug');
338341

@@ -347,4 +350,25 @@ module('Acceptance | version navigation', function (hooks) {
347350
.includesText('v4.0')
348351
.hasAttribute('href', '/ember/4.0');
349352
});
353+
354+
test('switching to a version that is missing a function offers a link to the API index for that version', async function (assert) {
355+
await visit('/ember/3.28/functions/@glimmer%2Ftracking/tracked');
356+
assert.strictEqual(
357+
currentURL(),
358+
'/ember/3.28/functions/@glimmer%2Ftracking/tracked',
359+
);
360+
361+
await selectChoose('.ember-power-select-trigger', '3.12');
362+
363+
assert
364+
.dom()
365+
.includesText(
366+
'We could not find function @glimmer/tracking/tracked in v3.12 of ember.',
367+
);
368+
369+
assert
370+
.dom(versionIndexLinkSelector)
371+
.includesText('v3.12')
372+
.hasAttribute('href', '/ember/3.12');
373+
});
350374
});

0 commit comments

Comments
 (0)