@@ -112,19 +112,27 @@ export class AcpGeneratorFormatExitError extends Schema.TaggedErrorClass<AcpGene
112112
113113export class AcpGeneratorSchemaValueDeclarationMissingError extends Schema . TaggedErrorClass < AcpGeneratorSchemaValueDeclarationMissingError > ( ) (
114114 "AcpGeneratorSchemaValueDeclarationMissingError" ,
115- { typeDeclaration : Schema . String } ,
115+ {
116+ lineIndex : Schema . Number ,
117+ typeDeclarationLength : Schema . Number ,
118+ nextLinePresent : Schema . Boolean ,
119+ nextLineLength : Schema . optional ( Schema . Number ) ,
120+ } ,
116121) {
117122 override get message ( ) : string {
118- return `Generated ACP schema type declaration has no following value declaration: ${ this . typeDeclaration } ` ;
123+ return `Generated ACP schema type declaration at line ${ this . lineIndex + 1 } has no following value declaration. ` ;
119124 }
120125}
121126
122127export class AcpGeneratorSchemaNameParseError extends Schema . TaggedErrorClass < AcpGeneratorSchemaNameParseError > ( ) (
123128 "AcpGeneratorSchemaNameParseError" ,
124- { typeDeclaration : Schema . String } ,
129+ {
130+ lineIndex : Schema . Number ,
131+ typeDeclarationLength : Schema . Number ,
132+ } ,
125133) {
126134 override get message ( ) : string {
127- return `Could not extract an ACP schema name from generated declaration: ${ this . typeDeclaration } ` ;
135+ return `Could not extract an ACP schema name from generated declaration at line ${ this . lineIndex + 1 } . ` ;
128136 }
129137}
130138
@@ -313,9 +321,7 @@ const writeGeneratedFiles = Effect.fn("writeGeneratedFiles")(function* (
313321 yield * fs . writeFileString ( metaOutputPath , metaOutput ) ;
314322} ) ;
315323
316- function collectSchemaEntries (
317- chunk : string ,
318- ) : ReadonlyArray < { readonly name : string ; readonly code : string } > {
324+ export const collectSchemaEntries = Effect . fn ( "collectSchemaEntries" ) ( function * ( chunk : string ) {
319325 const lines = chunk
320326 . split ( "\n" )
321327 . map ( ( line ) => line . trim ( ) )
@@ -330,14 +336,20 @@ function collectSchemaEntries(
330336
331337 const constLine = lines [ index + 1 ] ;
332338 if ( ! constLine ?. startsWith ( "export const " ) ) {
333- throw new AcpGeneratorSchemaValueDeclarationMissingError ( {
334- typeDeclaration : typeLine ,
339+ return yield * new AcpGeneratorSchemaValueDeclarationMissingError ( {
340+ lineIndex : index ,
341+ typeDeclarationLength : typeLine . length ,
342+ nextLinePresent : constLine !== undefined ,
343+ ...( constLine === undefined ? { } : { nextLineLength : constLine . length } ) ,
335344 } ) ;
336345 }
337346
338347 const match = / ^ e x p o r t t y p e ( [ A - Z a - z 0 - 9 _ ] + ) / . exec ( typeLine ) ;
339348 if ( ! match ?. [ 1 ] ) {
340- throw new AcpGeneratorSchemaNameParseError ( { typeDeclaration : typeLine } ) ;
349+ return yield * new AcpGeneratorSchemaNameParseError ( {
350+ lineIndex : index ,
351+ typeDeclarationLength : typeLine . length ,
352+ } ) ;
341353 }
342354
343355 entries . push ( {
@@ -348,7 +360,7 @@ function collectSchemaEntries(
348360 }
349361
350362 return entries ;
351- }
363+ } ) ;
352364
353365function normalizeNullableTypes ( value : Schema . Json ) : Schema . Json {
354366 if ( Array . isArray ( value ) ) {
@@ -431,7 +443,8 @@ const generateSchemas = Effect.fn("generateSchemas")(function* (skipDownload: bo
431443
432444 const output = generator . generate ( "openapi-3.1" , normalizedDefinitions as never , false ) . trim ( ) ;
433445 if ( output . length > 0 ) {
434- for ( const entry of collectSchemaEntries ( output ) ) {
446+ const schemaEntries = yield * collectSchemaEntries ( output ) ;
447+ for ( const entry of schemaEntries ) {
435448 if ( ! generatedEntries . has ( entry . name ) ) {
436449 generatedEntries . set ( entry . name , entry . code ) ;
437450 }
0 commit comments