Skip to content

Commit d506182

Browse files
committed
fix(acp): yield schema errors as typed Effect failures instead of throwing
Convert collectSchemaEntries from a plain function to an Effect.fn so that AcpGeneratorSchemaValueDeclarationMissingError and AcpGeneratorSchemaNameParseError are yielded as typed failures (matching the pattern used by other generator errors) rather than thrown synchronously, which would make them defects unreachable via Effect.catchTag.
1 parent 162cbae commit d506182

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

packages/effect-acp/scripts/generate.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,7 @@ const writeGeneratedFiles = Effect.fn("writeGeneratedFiles")(function* (
313313
yield* fs.writeFileString(metaOutputPath, metaOutput);
314314
});
315315

316-
function collectSchemaEntries(
317-
chunk: string,
318-
): ReadonlyArray<{ readonly name: string; readonly code: string }> {
316+
const collectSchemaEntries = Effect.fn("collectSchemaEntries")(function* (chunk: string) {
319317
const lines = chunk
320318
.split("\n")
321319
.map((line) => line.trim())
@@ -330,14 +328,14 @@ function collectSchemaEntries(
330328

331329
const constLine = lines[index + 1];
332330
if (!constLine?.startsWith("export const ")) {
333-
throw new AcpGeneratorSchemaValueDeclarationMissingError({
331+
return yield* new AcpGeneratorSchemaValueDeclarationMissingError({
334332
typeDeclaration: typeLine,
335333
});
336334
}
337335

338336
const match = /^export type ([A-Za-z0-9_]+)/.exec(typeLine);
339337
if (!match?.[1]) {
340-
throw new AcpGeneratorSchemaNameParseError({ typeDeclaration: typeLine });
338+
return yield* new AcpGeneratorSchemaNameParseError({ typeDeclaration: typeLine });
341339
}
342340

343341
entries.push({
@@ -348,7 +346,7 @@ function collectSchemaEntries(
348346
}
349347

350348
return entries;
351-
}
349+
});
352350

353351
function normalizeNullableTypes(value: Schema.Json): Schema.Json {
354352
if (Array.isArray(value)) {
@@ -431,7 +429,7 @@ const generateSchemas = Effect.fn("generateSchemas")(function* (skipDownload: bo
431429

432430
const output = generator.generate("openapi-3.1", normalizedDefinitions as never, false).trim();
433431
if (output.length > 0) {
434-
for (const entry of collectSchemaEntries(output)) {
432+
for (const entry of yield* collectSchemaEntries(output)) {
435433
if (!generatedEntries.has(entry.name)) {
436434
generatedEntries.set(entry.name, entry.code);
437435
}

0 commit comments

Comments
 (0)