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

Error messages set to vfile by Remark plugins are not reported. #9953

Open
7 tasks done
niravcodes opened this issue Mar 15, 2024 · 1 comment
Open
7 tasks done

Error messages set to vfile by Remark plugins are not reported. #9953

niravcodes opened this issue Mar 15, 2024 · 1 comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: markdown Related to Markdown parsing or syntax

Comments

@niravcodes
Copy link

niravcodes commented Mar 15, 2024

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Remark plugins need to issue warnings and create errors when processing mdx files. They can do so using the vfile.message mechanism already.

The messages can be reported with the vfile-reporter utility. The reporter presents the messages in a convenient way, grouping messages by file and linking each error to the reported line and column number in the mdx document.

However, when Docusaurus applies a Remark plugin to a mdx document, it doesn't report the warnings and errors.

I can kind of get around it by writing a new Remark plugin, and putting it at the end of the pipeline:

import { reporter } from "vfile-reporter";
export default function reporter() {
  return (_, vfile) => {
    console.error(reporter(vfile));
  };
}

but this is not very neat as the plugins are executed multiple times during docusaurus start and it relentlessly spams the terminal. To experience this, uncomment the [require("./plugins/plugin-reporting.js"), {}], line (line 51, docusaurus.config.js) in the bug repro.

Reproducible demo

https://codesandbox.io/p/devbox/priceless-meadow-dq4n4h?file=%2Fplugins%2Fplugin-erroring.js%3A3%2C59

Steps to reproduce

In any remark plugin, add a vfile.message("message") line. It should show up but doesn't.

Check the codesandbox repro for demo.

Expected behavior

I expect the messages that the Remark plugins set on vfiles are reported by Docusaurus either by default or as a simple config toggle.

Actual behavior

The messages are never shown.

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@niravcodes niravcodes added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Mar 15, 2024
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Mar 15, 2024
@slorber
Copy link
Collaborator

slorber commented Mar 15, 2024

Agree we should have that 👍

Historically we never used those Unified/Vfile reporting APIs, but we should

@Josh-Cena Josh-Cena added the domain: markdown Related to Markdown parsing or syntax label Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: markdown Related to Markdown parsing or syntax
Projects
None yet
Development

No branches or pull requests

4 participants
@slorber @niravcodes @Josh-Cena and others