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

RangeError: Invalid count value when running "parse-pages" #4

Open
Vadorequest opened this issue Oct 18, 2022 · 2 comments
Open

RangeError: Invalid count value when running "parse-pages" #4

Vadorequest opened this issue Oct 18, 2022 · 2 comments

Comments

@Vadorequest
Copy link

Running yarn parse-pages -- Communication yields error:

data/Communication/reseaux-sociaux/unly/twitter.json -> data/Communication/reseaux-sociaux/unly/twitter.md
file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:70
      block += " ".repeat((this.listCount.length - 1) * 2);
                   ^

RangeError: Invalid count value
    at String.repeat (<anonymous>)
    at MarkdownRenderer.renderBlock (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:70:20)
    at MarkdownRenderer.renderNode (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:31:24)
    at MarkdownRenderer.renderChildren (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:136:22)
    at getChildren (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:52:36)
    at MarkdownRenderer.renderBlock (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:96:15)
    at MarkdownRenderer.renderNode (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:31:24)
    at MarkdownRenderer.renderChildren (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:136:22)
    at MarkdownRenderer.renderNode (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:28:24)
    at MarkdownRenderer.render (file:///Users/vadorequest/dev/gitbook-to-md/built/MarkdownRenderer.js:22:46)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Document data/Communication/reseaux-sociaux/unly/twitter.json:

{"id":"-LY7NG876FvrUg1fVjZN","title":"Twitter","kind":"sheet","description":"La page corpo de la marque","path":"reseaux-sociaux/unly/twitter","slug":"twitter","pages":[],"document":{"object":"document","data":{"schemaVersion":5},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"OBJECTIF : ","marks":[{"object":"mark","type":"bold","data":{}}],"selections":[]},{"object":"leaf","text":"Notoriété et trafic","marks":[],"selections":[]}]}]},{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"CIBLE : ","marks":[{"object":"mark","type":"bold","data":{}}],"selections":[]},{"object":"leaf","text":"BtoB","marks":[],"selections":[]}]}]},{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"TON :  ","marks":[{"object":"mark","type":"bold","data":{}}],"selections":[]},{"object":"leaf","text":"Soutenu / professionnel","marks":[],"selections":[]}]}]},{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"THÉMATIQUES DES POSTS :","marks":[{"object":"mark","type":"bold","data":{}}],"selections":[]}]}]},{"object":"block","type":"list-unordered","isVoid":false,"data":{},"nodes":[{"object":"block","type":"list-item","isVoid":false,"data":{},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"Actualités sur le secteur EdTech et FinTech","marks":[],"selections":[]}]}]}]},{"object":"block","type":"list-item","isVoid":false,"data":{},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"Annonces/lancement de solutions","marks":[],"selections":[]}]}]}]},{"object":"block","type":"list-item","isVoid":false,"data":{},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"Annonces de projets de partenariats/ de développement > place du réseautage","marks":[],"selections":[]}]}]}]},{"object":"block","type":"list-item","isVoid":false,"data":{},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"Relations client/ partenariat/ presse (remerciement, identification, clin d’œil…)","marks":[],"selections":[]}]}]}]},{"object":"block","type":"list-item","isVoid":false,"data":{},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"Evénements professionnels (colloques, conférences, salon…)","marks":[],"selections":[]}]}]}]},{"object":"block","type":"list-item","isVoid":false,"data":{},"nodes":[{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"Relai des résultats du baromètre","marks":[],"selections":[]}]}]}]}]},{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"ACTION : ","marks":[{"object":"mark","type":"bold","data":{}}],"selections":[]},{"object":"leaf","text":"retweet des posts de partenaires, presse (articles sur Unly et du secteur) et figures d’influence","marks":[],"selections":[]}]}]},{"object":"block","type":"paragraph","isVoid":false,"data":{},"nodes":[{"object":"text","leaves":[{"object":"leaf","text":"","marks":[],"selections":[]}]}]}]}}

Deleting the document and re-running the command fixes the issue, must be something that isn't properly handled (edge case)

@Vadorequest
Copy link
Author

It also happened when the JSON file was completely empty.

@Vadorequest
Copy link
Author

Vadorequest commented Oct 18, 2022

Solution in src/convertToMarkdown.ts:

import { promises as fs } from 'fs';
import type { Files } from './MarkdownRenderer.js';
import MarkdownRenderer from './MarkdownRenderer.js';

export default async (filename: string, files: Files = {}) => {
  const renderer = new MarkdownRenderer(files);
  const file = await fs.readFile(filename, 'utf8');

  try {
    const data = JSON.parse(file);
    const output = data.kind == 'sheet' ? renderer.render(data.document) : undefined;

    return output;
  } catch (e) {
    console.error(`The file "${filename}" couldn't be JSON parsed.`, e, file);

    return null;
  }
};

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

No branches or pull requests

1 participant