MCPcopy Create free account
hub / github.com/vercel/vercel / parseConfig

Function parseConfig

packages/python-analysis/src/util/config.ts:60–85  ·  view source on GitHub ↗
(
  content: string,
  filename: string,
  schema: z.ZodType<T>,
  filetype: string | undefined = undefined
)

Source from the content-addressed store, hash-verified

58 * @returns Validated and typed config object
59 */
60export function parseConfig<T>(
61 content: string,
62 filename: string,
63 schema: z.ZodType<T>,
64 filetype: string | undefined = undefined
65): T {
66 const raw = parseRawConfig(content, filename, filetype);
67
68 const result = schema.safeParse(raw);
69 if (!result.success) {
70 const issues = result.error.issues
71 .map(issue => {
72 const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
73 return ` - ${path}: ${issue.message}`;
74 })
75 .join('\n');
76 throw new PythonAnalysisError({
77 message: `Invalid config in "${filename}":\n${issues}`,
78 code: 'PYTHON_CONFIG_VALIDATION_ERROR',
79 path: filename,
80 fileContent: content,
81 });
82 }
83
84 return result.data;
85}
86
87/**
88 * Read a config file if it exists and validate it against a zod schema.

Callers 1

readConfigIfExistsFunction · 0.85

Calls 2

parseRawConfigFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected