mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
TypeScript: Improve error message
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'fumadocs-typescript': patch
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Improve error message
|
||||
@@ -6,7 +6,6 @@ import type { SourceMap, TransformPluginContext } from 'rollup';
|
||||
import type { TransformResult } from 'vite';
|
||||
import { parse } from 'node:querystring';
|
||||
import { ValidationError } from '@/utils/validation';
|
||||
import path from 'node:path';
|
||||
import type { LoaderContext } from 'webpack';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
@@ -165,9 +164,6 @@ export function toWebpack(loader: Loader): WebpackLoader {
|
||||
}
|
||||
|
||||
if (!(error instanceof Error)) throw error;
|
||||
|
||||
const fpath = path.relative(this.context, this.resourcePath);
|
||||
error.message = `${fpath}:${error.name}: ${error.message}`;
|
||||
callback(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -215,21 +215,33 @@ export function remarkAutoTypeTable(
|
||||
|
||||
visit(tree, 'mdxJsxFlowElement', (node) => {
|
||||
if (node.name !== name) return;
|
||||
const props: Record<string, string | null> = {};
|
||||
const props: Record<string, string | true> = {};
|
||||
const onError = (message: string, cause?: Error) => {
|
||||
const location = node.position
|
||||
? `${file.path}:${node.position.start.line}:${node.position.start.column}`
|
||||
: file.path;
|
||||
throw new Error(`${location} from <auto-type-table>: ${message}`, {
|
||||
cause,
|
||||
});
|
||||
};
|
||||
|
||||
for (const attr of node.attributes) {
|
||||
if (
|
||||
attr.type !== 'mdxJsxAttribute' ||
|
||||
(typeof attr.value !== 'string' && attr.value !== null)
|
||||
)
|
||||
throw new Error(
|
||||
'`auto-type-table` only support string & boolean attributes',
|
||||
);
|
||||
|
||||
props[attr.name] = attr.value;
|
||||
if (attr.type !== 'mdxJsxAttribute') {
|
||||
onError('only named attributes are allowed.');
|
||||
} else if (typeof attr.value === 'string') {
|
||||
props[attr.name] = attr.value;
|
||||
} else if (attr.value === null) {
|
||||
props[attr.name] = true;
|
||||
} else {
|
||||
onError('only string & boolean attributes are allowed.');
|
||||
}
|
||||
}
|
||||
|
||||
queue.push(run(node, props));
|
||||
queue.push(
|
||||
run(node, props).catch((err) => {
|
||||
onError('failed to generate type table', err);
|
||||
}),
|
||||
);
|
||||
return 'skip';
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user