LionWeb-io / lionweb-repository

Reference implementation of LionWeb repository
Apache License 2.0
2 stars 1 forks source link

Tree with no containments crash repository #6

Closed ftomassetti closed 6 months ago

ftomassetti commented 7 months ago

I am inserting a tree with a single node (the root). The concept of the root itself does not specify containments: that concept can just have two properties.

When trying to store it I get:

Comparing chunks
STORE.CHANGES
[
  '    LanguageAdded: Language with  key language-com.strumenta.filestorage-key and version 1 is added at $.languages[0] ',
  '    NodeAdded: Node file_src/main/kotlin/com/strumenta/codebaseanalyzerFileStorageLanguage.kt is added at $.nodes[0] '
]
LionWebQueries.getNodeTree for
/Users/ftomassetti/repos/lionweb-repository/node_modules/pg-promise/lib/helpers/methods/insert.js:100
        throw new TypeError('Cannot generate an INSERT from an empty array.');
              ^

TypeError: Cannot generate an INSERT from an empty array.
    at Object.insert (/Users/ftomassetti/repos/lionweb-repository/node_modules/pg-promise/lib/helpers/methods/insert.js:100:15)
    at Object.insert (/Users/ftomassetti/repos/lionweb-repository/node_modules/pg-promise/lib/helpers/index.js:52:27)
    at LionWebQueries.<anonymous> (file:///Users/ftomassetti/repos/lionweb-repository/build/database/LionWebQueries.js:375:56)
    at Generator.next (<anonymous>)
    at fulfilled (file:///Users/ftomassetti/repos/lionweb-repository/build/database/LionWebQueries.js:4:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.14.0
[nodemon] app crashed - waiting for file changes before starting...

The LionWebQueries.js lines are:

                // INSERT Containments
                const insertRowData = tbsNodesToCreate.flatMap(node => node.containments.map(c => ({ node_id: node.id, containment: c.containment, children: c.children })));
                const insertContainments = pgp.helpers.insert(insertRowData, containmentsColumnSet);
                yield db.query(insertContainments);

The problem seems to be pgp.helpers.insert(insertRowData, containmentsColumnSet); and with the first parameter in particular. So I guess that if insertRowData is empty we should skip the call to insert

joswarmer commented 6 months ago

You are right, we should always first check whether something that gets inserted is not null or empty. Probably need to add such a check at other places as well.

joswarmer commented 6 months ago

Fixed this one and (hopefully) all others of this type in branch reference-changes

joswarmer commented 6 months ago

Fixed in main branch