Skip to content

Commit 892e813

Browse files
fix: prevent adding molecule when molfile is corrupted
1 parent a8ba97a commit 892e813

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/data/molecules/MoleculeManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Molecule } from 'openchemlib';
44
import type { StateMolecule, StateMoleculeExtended } from './Molecule.js';
55
import { initMolecule } from './Molecule.js';
66

7+
//TODO: Move molecule initialization to nmrium-core and log an error if the molecule cannot be parsed.
78
export function fromJSON(
89
mols: StateMolecule[],
910
reservedMolecules: StateMolecule[] = [],
@@ -13,6 +14,13 @@ export function fromJSON(
1314
const molecules: StateMoleculeExtended[] = [];
1415
for (const mol of mols) {
1516
const molecule = Molecule.fromMolfile(mol.molfile);
17+
18+
const atomCount = molecule.getAllAtoms();
19+
20+
if (atomCount === 0) {
21+
continue;
22+
}
23+
1624
molecules.push(
1725
initMolecule({
1826
molfile: molecule.toMolfileV3(),

0 commit comments

Comments
 (0)