Skip to content

Commit 9472281

Browse files
committed
add additional sanity checks for data returned by loaders
1 parent 073cdc3 commit 9472281

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/content/loaders/funding.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ export function fundingLoader(options: { orcid: string }): Loader {
6262

6363
logger.info(`Successfully processed ${grants.length} grants`);
6464

65+
// Sanity checks
66+
if (grants.length === 0) {
67+
throw new Error('Funding loader returned 0 grants - this is likely an error');
68+
}
69+
70+
const grantsWithoutName = grants.filter((g: any) => !g.name || g.name.trim() === '' || g.name === 'Untitled Grant');
71+
if (grantsWithoutName.length > 0) {
72+
throw new Error(`${grantsWithoutName.length} grants missing proper title - data quality issue`);
73+
}
74+
6575
store.set({
6676
id: 'funding_loaded',
6777
data: {

src/content/loaders/github.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ export function githubLoader(options: {
132132

133133
logger.info(`Total teams processed: ${allTeams.length}`);
134134

135+
// Sanity checks
136+
if (allTeams.length === 0) {
137+
throw new Error('GitHub loader returned 0 teams - this is likely an error');
138+
}
139+
140+
const totalMembers = allTeams.reduce((sum, team) => sum + team.members.length, 0);
141+
if (totalMembers === 0) {
142+
throw new Error('GitHub loader returned 0 team members across all teams - this is likely an error');
143+
}
144+
145+
const teamsWithoutMembers = allTeams.filter(team => team.members.length === 0);
146+
if (teamsWithoutMembers.length > 0) {
147+
logger.warn(`${teamsWithoutMembers.length} teams have no members: ${teamsWithoutMembers.map(t => t.name).join(', ')}`);
148+
}
149+
135150
store.set({
136151
id: 'teams_loaded',
137152
data: {

src/content/loaders/google-sheets.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export function googleSheetsLoader(config: GoogleSheetsConfig): Loader {
2626

2727
const csvText = await response.text();
2828
const rows = csvText.split('\n').filter(row => row.trim());
29-
29+
30+
// Sanity check: ensure we got data
31+
if (rows.length <= 1) {
32+
throw new Error(`Google Sheets loader for "${sheetName}" returned no data rows - expected at least 1`);
33+
}
34+
3035
// Skip header row and process data rows
3136
for (let i = 1; i < rows.length; i++) {
3237
const row = parseCSVRow(rows[i]);

src/content/loaders/orcid.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ export function orcidLoader(options: { orcid: string }): Loader {
241241

242242
logger.info(`Successfully processed ${allPublications.length} publications from ORCID`);
243243

244+
// Sanity checks
245+
if (allPublications.length < 10) {
246+
throw new Error(`ORCID loader returned only ${allPublications.length} publications - expected at least 10`);
247+
}
248+
249+
const publicationsWithoutTitle = allPublications.filter(p => !p.title || p.title.trim() === '');
250+
if (publicationsWithoutTitle.length > 0) {
251+
throw new Error(`${publicationsWithoutTitle.length} publications missing title - data quality issue`);
252+
}
253+
244254
allPublications.sort((a, b) => {
245255
// Publications without year go to the end
246256
if (!a.year && !b.year) {

0 commit comments

Comments
 (0)