Skip to content

Commit 572b4ab

Browse files
committed
Display a more helpful error when switching versions and a module or class is not found in the target version
1 parent b4380a3 commit 572b4ab

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

app/assets/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ section.event {
177177

178178
.whoops {
179179
display: flex;
180+
flex-direction: column;
180181
justify-content: center;
181182
align-items: center;
182183
padding: var(--spacing-6);

app/routes/project-version/classes/class.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,26 @@ export default class ClassRoute extends Route {
5959
});
6060
}
6161

62-
redirect(model) {
62+
redirect(model, transition) {
6363
if (model.isError) {
64+
// Transitioning to the same route, probably only changing version
65+
// Could explicitly check by comparing transition.to and transition.from
66+
if (transition.to.name === transition?.from?.name) {
67+
const projectVersionRouteInfo = transition.to.find(function (item) {
68+
return item.params?.project_version;
69+
});
70+
const attemptedVersion =
71+
projectVersionRouteInfo.params?.project_version;
72+
const attemptedProject = projectVersionRouteInfo.params?.project;
73+
let error = new Error(
74+
`We could not find ${transition.to.localName} ${transition.to.params[transition.to.paramNames[0]]} in v${attemptedVersion} of ${attemptedProject}.`,
75+
);
76+
error.status = 404;
77+
error.attemptedProject = attemptedProject;
78+
error.attemptedVersion = attemptedVersion;
79+
throw error;
80+
}
81+
6482
let error = new Error(
6583
'Error retrieving model in routes/project-version/classes/class',
6684
);

app/templates/error.hbs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
<article class="whoops">
22
{{#if (eq this.model.status 404)}}
33
<h2 class="whoops__title">Ack! 404 friend, you're in the wrong place</h2>
4-
<div class="whoops__message">
4+
{{#if this.model.attemptedVersion}}
5+
<h3>
6+
{{this.model.message}}
7+
</h3>
8+
<p>
9+
Modules, classes, and functions sometimes move around or are renamed across versions.
10+
Try the <LinkTo @route="project-version" @models={{array this.model.attemptedProject this.model.attemptedVersion}} data-test-version-index-link>v{{this.model.attemptedVersion}} API docs index.</LinkTo>
11+
</p>
12+
{{else}}
513
<p>
614
This page wasn't found. Please try the <LinkTo @route="index">API docs page</LinkTo>.
715
If you expected something else to be here, please file a <a href="https://github.com/ember-learn/ember-api-docs/issues/new" target="_blank" rel="noopener noreferrer">ticket</a>.
816
</p>
9-
</div>
17+
{{/if}}
1018
{{else}}
1119
<h2 class="whoops__title">
1220
Whoops! Something went wrong.

tests/acceptance/switch-versions-test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,40 @@ module('Acceptance | version navigation', function (hooks) {
279279
'navigated to v1.13 class',
280280
);
281281
});
282+
283+
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) {
284+
const versionIndexLinkSelector = '[data-test-version-index-link]';
285+
await visit('/ember/6.4/modules/@glimmer%2Ftracking%2Fprimitives%2Fcache');
286+
assert.strictEqual(
287+
currentURL(),
288+
'/ember/6.4/modules/@glimmer%2Ftracking%2Fprimitives%2Fcache',
289+
);
290+
291+
await selectChoose('.ember-power-select-trigger', '3.10');
292+
293+
assert
294+
.dom()
295+
.includesText(
296+
'We could not find module @glimmer/tracking/primitives/cache in v3.10 of ember.',
297+
);
298+
299+
assert
300+
.dom(versionIndexLinkSelector)
301+
.includesText('v3.10')
302+
.hasAttribute('href', '/ember/3.10');
303+
304+
await visit('/ember/3.0/classes/Ember.Debug');
305+
assert.strictEqual(currentURL(), '/ember/3.0/classes/Ember.Debug');
306+
307+
await selectChoose('.ember-power-select-trigger', '4.0');
308+
309+
assert
310+
.dom()
311+
.includesText('We could not find class Ember.Debug in v4.0 of ember.');
312+
313+
assert
314+
.dom(versionIndexLinkSelector)
315+
.includesText('v4.0')
316+
.hasAttribute('href', '/ember/4.0');
317+
});
282318
});

0 commit comments

Comments
 (0)