Ver código fonte

Add defensive checks for undefined paths in context retrieval

Tobi Lutke 5 meses atrás
pai
commit
b848000ce4
1 arquivos alterados com 6 adições e 0 exclusões
  1. 6 0
      src/store.ts

+ 6 - 0
src/store.ts

@@ -1063,12 +1063,18 @@ export function getContextForPath(db: Database, collectionName: string, path: st
  * Legacy function for backward compatibility - resolves filepath to collection+path first
  */
 export function getContextForFile(db: Database, filepath: string): string | null {
+  // Handle undefined or null filepath
+  if (!filepath) return null;
+
   // Get all collections from YAML config
   const collections = collectionsListCollections();
   const config = collectionsLoadConfig();
 
   // Find which collection this absolute path belongs to
   for (const coll of collections) {
+    // Skip collections with missing paths
+    if (!coll || !coll.path) continue;
+
     if (filepath.startsWith(coll.path + '/') || filepath === coll.path) {
       // Extract relative path
       const relativePath = filepath.startsWith(coll.path + '/')