Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setCreationIds (and therefore things like .getInfo) Errors uncleanly on files with no creationIDs set #80

Closed
MP70 opened this issue Oct 27, 2023 · 1 comment

Comments

@MP70
Copy link
Collaborator

MP70 commented Oct 27, 2023

Even with useCreationIds: false,

Can we make it cleaner by either

  • A) not running if useCreationIds is false
  • B) catch the error nicely
  • C) Is it at all possible to just names in case of useCreationIds: false? (I'm looking at my getTextIds helper and that is what I did there.
    -- added debug here
  async getCreationIds(): Promise<SlideInfo[]> {
    const archive = this.archive;
    const relationships = await XmlHelper.getTargetsByRelationshipType(
      archive,
      this.path,
      this.relType,
    );
  
    const creationIds: SlideInfo[] = [];
    for (const slideRel of relationships) {
      try {
        const slideXml = await XmlHelper.getXmlFromArchive(
          archive,
          'ppt/' + slideRel.file,
        );
        
        if (!slideXml) {
          console.warn(`slideXml is undefined for file ${slideRel.file}`);
          continue;
        }
  
        const creationIdItem = slideXml.getElementsByTagName('p14:creationId').item(0);
  
        if (!creationIdItem) {
          console.warn(`No 'p14:creationId' tag found in ${slideRel.file}`);
          continue;
        }
  
        const creationIdSlide = creationIdItem.getAttribute('val');
  
        if (!creationIdSlide) {
          console.warn(`Attribute 'val' is undefined in ${slideRel.file}`);
          continue;
        }
  
        const elementIds = this.elementCreationIds(slideXml, archive);
        const slideInfo = await this.getSlideInfo(
          slideXml,
          archive,
          slideRel.file,
        );
  
        creationIds.push({
          id: Number(creationIdSlide),
          number: this.parseSlideRelFile(slideRel.file),
          elements: elementIds,
          info: slideInfo,
        });
      } catch (err) {
        console.error(`An error occurred while processing ${slideRel.file}:`, err);
      }
    }
  
    return creationIds.sort((slideA, slideB) => 
      slideA.number < slideB.number ? -1 : 1
    );
  }

Old error

 TypeError: Cannot read properties of undefined (reading 'getAttribute')

New error

 console.warn
      No 'p14:creationId' tag found in slides/slide1.xml

      47 |   
      48 |         if (!creationIdItem) {
    > 49 |           console.warn(`No 'p14:creationId' tag found in ${slideRel.file}`);
         |                   ^
      50 |           continue;
      51 |         }
      52 |   

Repro steps. -- chuck in a getInfo or setCreationIds into the get-all-text-elements test file

@singerla
Copy link
Owner

Hi @MP70 ! Thanks a lot for the efforts so far! I need to go deeper into this next week. Have a nice weekend! We'll proceed on Monday 👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants