Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions ui/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ export async function fetchCommunityMembers(): Promise<{members: CommunityMember
console.error('Failed to fetch data from:', dataUrl, 'Status:', response.status);
throw new Error('Failed to fetch static data');
}
const text = await response.text();
const lines = text.trim().split('\n');
const text = await response.text();
console.log('Response text length:', text.length);
console.log('Response text preview:', text.substring(0, 200));

const lines = text.trim().split('\n');
console.log('Number of lines:', lines.length);
console.log('First line:', lines[0]);

// Parse JSONL data
const kgData = lines.map(line => JSON.parse(line));
const kgData = lines.map((line, index) => {
try {
return JSON.parse(line);
} catch (error) {
console.error(`Error parsing line ${index}:`, line, error);
throw error;
}
});
Comment on lines +18 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change attempts to fix a JSON parsing error by adding more detailed error logging. However, the root cause of the error is a misunderstanding of the API response format.

The API endpoint /api/data returns a single JSON object, not a JSONL stream. Therefore, trying to parse it line-by-line will fail, leading to the SyntaxError.

Additionally, the API already performs the data transformation from raw knowledge graph entries to community members, including generating categories. The client-side transformation logic that follows this block is redundant and inefficient.

The correct approach is to parse the entire response as a single JSON object and use the data directly. This also has the benefit of removing the temporary console.log statements.

I suggest replacing this block with code that parses the JSON and returns the data. This will make the subsequent transformation code in this function redundant, and it should be removed.

Suggested change
const text = await response.text();
console.log('Response text length:', text.length);
console.log('Response text preview:', text.substring(0, 200));
const lines = text.trim().split('\n');
console.log('Number of lines:', lines.length);
console.log('First line:', lines[0]);
// Parse JSONL data
const kgData = lines.map(line => JSON.parse(line));
const kgData = lines.map((line, index) => {
try {
return JSON.parse(line);
} catch (error) {
console.error(`Error parsing line ${index}:`, line, error);
throw error;
}
});
const data = await response.json();
return { members: data.materials, categories: data.categories };


// Transform to community members
const members: CommunityMember[] = [];
Expand Down
Loading