Skip to content

Commit 8550293

Browse files
authored
Clearer error message from learning tracks (#32538)
1 parent 0a6e3ee commit 8550293

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/process-learning-tracks.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export default async function processLearningTracks(rawLearningTracks, context)
1111

1212
let featuredTrack
1313

14+
if (!context.currentProduct) {
15+
throw new Error(`Missing context.currentProduct value.`)
16+
}
17+
1418
for (const rawTrackName of rawLearningTracks) {
1519
let isFeaturedTrack = false
1620

@@ -19,9 +23,13 @@ export default async function processLearningTracks(rawLearningTracks, context)
1923
if (!renderedTrackName) continue
2024

2125
// Find the data for the current product and track name.
22-
const track = context.site.data['learning-tracks'][context.currentProduct][renderedTrackName]
26+
const trackDataForProduct = context.site.data['learning-tracks'][context.currentProduct]
27+
if (!trackDataForProduct) {
28+
throw new Error(`No learning track data for product "${context.currentProduct}".`)
29+
}
30+
const track = trackDataForProduct[renderedTrackName]
2331
if (!track) {
24-
throw new Error(`no learning track called '${renderedTrackName}'.`)
32+
throw new Error(`No learning track called '${renderedTrackName}'.`)
2533
}
2634

2735
// If there is no `versions` prop in the learning track frontmatter, assume the track should display in all versions.

0 commit comments

Comments
 (0)