Fix MDX integration error message not being compatible with docs (#5767)
* fix(errors): Fix MDX Integration missing error message so docs generation work properly * docs(errors): Add more information regarding authoring error messages
This commit is contained in:
parent
17608762e1
commit
f1da0da29f
3 changed files with 16 additions and 8 deletions
|
@ -56,6 +56,17 @@ If you are unsure about which error code to choose, ask [Erika](https://github.c
|
|||
- **Error codes and names are permanent**, and should never be changed, nor deleted. Users should always be able to find an error by searching, and this ensures a matching result. When an error is no longer relevant, it should be deprecated, not removed.
|
||||
- Contextual information may be used to enhance the message or the hint. However, the code that caused the error or the position of the error should not be included in the message as they will already be shown as part of the error.
|
||||
- Do not prefix `title`, `message` and `hint` with descriptive words such as "Error:" or "Hint:" as it may lead to duplicated labels in the UI / CLI.
|
||||
- Dynamic error messages must use the following shape:
|
||||
|
||||
```js
|
||||
message: (arguments) => `text ${substitute}`
|
||||
```
|
||||
|
||||
Please avoid including too much logic inside the errors if you can. The last thing you want is for a bug to happen inside what's already an error!
|
||||
|
||||
If the different arguments needs processing before being shown (ex: `toString`, `JSON.stringify`), the processing should happen where the error is thrown and not inside the message itself.
|
||||
|
||||
Using light logic to add / remove different parts of the message is okay, however make sure to include a `@message` tag in the JSDoc comment for the auto-generated documentation. See below for more information.
|
||||
|
||||
### Documentation support through JSDoc
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ export function enhanceViteSSRError({
|
|||
) {
|
||||
safeError = new AstroError({
|
||||
...AstroErrorData.MdxIntegrationMissingError,
|
||||
message: AstroErrorData.MdxIntegrationMissingError.message(fileId),
|
||||
message: AstroErrorData.MdxIntegrationMissingError.message(JSON.stringify(fileId)),
|
||||
location: safeError.loc,
|
||||
stack: safeError.stack,
|
||||
}) as ErrorWithMetadata;
|
||||
|
|
|
@ -544,11 +544,8 @@ See https://docs.astro.build/en/guides/server-side-rendering/ for more informati
|
|||
MdxIntegrationMissingError: {
|
||||
title: 'MDX integration missing.',
|
||||
code: 6004,
|
||||
message: (id: string) => {
|
||||
return `Unable to render ${JSON.stringify(
|
||||
id
|
||||
)}. Ensure that the \`@astrojs/mdx\` integration is installed.`;
|
||||
},
|
||||
message: (file: string) =>
|
||||
`Unable to render ${file}. Ensure that the \`@astrojs/mdx\` integration is installed.`,
|
||||
hint: 'See the MDX integration docs for installation and usage instructions: https://docs.astro.build/en/guides/integrations-guide/mdx/',
|
||||
},
|
||||
// Config Errors - 7xxx
|
||||
|
|
Loading…
Reference in a new issue