Parcourir la source

Media hotfix - ignore entities without schema (but add console.error) (#555)

* Media entities conversion - ignore and log error if empty

* Fix linter error

* Minor adjustment

* Minor change in error message and condition

Co-authored-by: Leszek Wiesner <l.wiesner@adawards.pl>
Lezek123 il y a 4 ans
Parent
commit
b3d47d0bd6

+ 10 - 5
pioneer/packages/joy-media/src/transport.substrate.ts

@@ -304,7 +304,7 @@ export class SubstrateTransport extends MediaTransport {
     const entityCodecResolver = await this.getEntityCodecResolver();
     const loadableClassIds = await this.classNamesToIdSet(ClassNamesThatRequireLoadingInternals);
 
-    const convertions: Promise<PlainEntity>[] = [];
+    const converted: PlainEntity[] = [];
     for (const entity of entities) {
       const classIdStr = entity.class_id.toString();
       const codec = entityCodecResolver.getCodecByClassId(entity.class_id);
@@ -315,16 +315,21 @@ export class SubstrateTransport extends MediaTransport {
       }
 
       const loadInternals = loadableClassIds.has(classIdStr);
-      convertions.push(
-        codec.toPlainObject(
+
+      try {
+        converted.push(await codec.toPlainObject(
           entity, {
             loadInternals,
             loadEntityById,
             loadChannelById
-          }));
+          })
+        );
+      } catch (conversionError) {
+        console.error(conversionError);
+      }
     }
 
-    return Promise.all(convertions);
+    return converted;
   }
 
   // Load entities by class name:

+ 4 - 0
types/src/versioned-store/EntityCodec.ts

@@ -200,6 +200,10 @@ export abstract class EntityCodec<T extends PlainEntity> {
       id: entity.id.toNumber()
     }
 
+    if (!entity.in_class_schema_indexes.toArray().length) {
+		throw new Error(`No schema support exists for entity! Entity id: ${res.id}`);
+	}
+
     for (const v of entity.entity_values) {
       const propIdx = v.in_class_index.toNumber();
       const propName = this.propIndexToNameMap.get(propIdx);