镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Doctool may swallow errors due to unhandled async functions #30090

Closed

Description

@Fishrock123

Basically, this code is not good:

fs.readFile(filename, 'utf8', async (er, input) => {
if (er) throw er;
const content = unified()
.use(markdown)
.use(html.preprocessText)
.use(json.jsonAPI, { filename })
.use(html.firstHeader)
.use(html.preprocessElements, { filename })
.use(html.buildToc, { filename, apilinks })
.use(remark2rehype, { allowDangerousHTML: true })
.use(raw)
.use(htmlStringify)
.processSync(input);
const basename = path.basename(filename, '.md');
const myHtml = await html.toHTML({ input, content, filename, nodeVersion });
const htmlTarget = path.join(outputDir, `${basename}.html`);
fs.writeFileSync(htmlTarget, myHtml);
const jsonTarget = path.join(outputDir, `${basename}.json`);
fs.writeFileSync(jsonTarget, JSON.stringify(content.json, null, 2));
});

Issues with that:

  • Async function set as a callback (unhandled)
  • sync I/O calls inside an async function
  • unified is synchronously invoked still

This is all the direct result of f4f856b, which is the result of something else. In hindsight, I wish I payed a bit more attention in my review of that.

Unfortunately my focus is elsewhere, so someone else should probably try to clean this up.

Activity

  1. added
    good first issueIssues that are suitable for first-time contributors.
    toolsIssues and PRs related to the tools directory.
    on Oct 23, 2019
  2. Purexo commented on Oct 23, 2019

    @Purexo

    Hi, I'd like to solve this issue for participate at Node.js wich is a runtime i like a lot.
    I've time tomorrow for rewrite this code.

    I'll give you some news tomorrow on my advancement.

    Maybe i'll commit with my pro account @tpoisseau

    best regards.

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

Metadata

Metadata

Assignees

Labels

good first issueIssues that are suitable for first-time contributors.toolsIssues and PRs related to the tools directory.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions