Handle null reference exceptions when rendering files context

This commit is contained in:
Debanjum
2025-08-15 15:59:57 -07:00
parent 20347e21c2
commit 7251b25c66

View File

@@ -467,9 +467,12 @@ export function constructAllReferences(
if (contextData) { if (contextData) {
let localContextReferences = contextData.map((context) => { let localContextReferences = contextData.map((context) => {
if (!context.compiled && context.compiled !== "") { if (!context.compiled && context.compiled !== "") {
const fileContent = context as unknown as string; const raw = context as unknown;
const title = fileContent.split("\n")[0]; const fileContent = typeof raw === "string" ? raw : raw == null ? "" : String(raw);
const content = fileContent.split("\n").slice(1).join("\n");
const lines = fileContent.split("\n");
const title = lines[0] && lines[0].trim() ? lines[0] : "(untitled)";
const content = lines.slice(1).join("\n");
return { return {
title: title, title: title,
content: content, content: content,