33import * as NodeRuntime from "@effect/platform-node/NodeRuntime" ;
44import * as NodeServices from "@effect/platform-node/NodeServices" ;
55import { make as makeJsonSchemaGenerator } from "@effect/openapi-generator/JsonSchemaGenerator" ;
6+ import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics" ;
67import * as Effect from "effect/Effect" ;
78import * as FileSystem from "effect/FileSystem" ;
89import * as Layer from "effect/Layer" ;
@@ -23,31 +24,47 @@ interface GeneratedPaths {
2324 readonly metaOutputPath : string ;
2425}
2526
27+ const urlDiagnosticsSchema = {
28+ urlInputLength : Schema . Number ,
29+ urlProtocol : Schema . optionalKey ( Schema . String ) ,
30+ urlHostname : Schema . optionalKey ( Schema . String ) ,
31+ } ;
32+
33+ function urlDiagnosticFields ( url : string ) {
34+ const diagnostics = getUrlDiagnostics ( url ) ;
35+ return {
36+ urlInputLength : diagnostics . inputLength ,
37+ ...( diagnostics . protocol === undefined ? { } : { urlProtocol : diagnostics . protocol } ) ,
38+ ...( diagnostics . hostname === undefined ? { } : { urlHostname : diagnostics . hostname } ) ,
39+ } ;
40+ }
41+
2642export class AcpGeneratorDownloadError extends Schema . TaggedErrorClass < AcpGeneratorDownloadError > ( ) (
2743 "AcpGeneratorDownloadError" ,
2844 {
29- url : Schema . String ,
45+ ... urlDiagnosticsSchema ,
3046 outputPath : Schema . String ,
3147 stage : Schema . Literals ( [ "request" , "read-response" ] ) ,
3248 cause : Schema . Defect ( ) ,
3349 } ,
3450) {
3551 override get message ( ) : string {
36- return `Failed to download ${ this . url } to ${ this . outputPath } during ${ this . stage } .` ;
52+ const source = this . urlHostname === undefined ? "the configured source" : this . urlHostname ;
53+ return `Failed to download the ACP generator input from ${ source } to ${ this . outputPath } during ${ this . stage } .` ;
3754 }
3855}
3956
4057export class AcpGeneratorDownloadFileError extends Schema . TaggedErrorClass < AcpGeneratorDownloadFileError > ( ) (
4158 "AcpGeneratorDownloadFileError" ,
4259 {
43- url : Schema . String ,
60+ ... urlDiagnosticsSchema ,
4461 outputPath : Schema . String ,
4562 stage : Schema . Literals ( [ "create-directory" , "write-file" ] ) ,
4663 cause : Schema . Defect ( ) ,
4764 } ,
4865) {
4966 override get message ( ) : string {
50- return `Failed to store the download from ${ this . url } at ${ this . outputPath } during ${ this . stage } .` ;
67+ return `Failed to store the ACP generator download at ${ this . outputPath } during ${ this . stage } .` ;
5168 }
5269}
5370
@@ -69,27 +86,27 @@ export class AcpGeneratorFormatProcessError extends Schema.TaggedErrorClass<AcpG
6986 {
7087 stage : Schema . Literals ( [ "spawn" , "wait-for-exit" ] ) ,
7188 command : Schema . String ,
72- args : Schema . Array ( Schema . String ) ,
89+ argumentCount : Schema . Number ,
7390 generatedDir : Schema . String ,
7491 cause : Schema . Defect ( ) ,
7592 } ,
7693) {
7794 override get message ( ) : string {
78- return `ACP generator formatting command ${ JSON . stringify ( [ this . command , ... this . args ] ) } failed during ${ this . stage } for ${ this . generatedDir } .` ;
95+ return `ACP generator formatting command ${ this . command } failed during ${ this . stage } for ${ this . generatedDir } .` ;
7996 }
8097}
8198
8299export class AcpGeneratorFormatExitError extends Schema . TaggedErrorClass < AcpGeneratorFormatExitError > ( ) (
83100 "AcpGeneratorFormatExitError" ,
84101 {
85102 command : Schema . String ,
86- args : Schema . Array ( Schema . String ) ,
103+ argumentCount : Schema . Number ,
87104 generatedDir : Schema . String ,
88105 exitCode : Schema . Number ,
89106 } ,
90107) {
91108 override get message ( ) : string {
92- return `ACP generator formatting command ${ JSON . stringify ( [ this . command , ... this . args ] ) } exited with code ${ this . exitCode } for ${ this . generatedDir } .` ;
109+ return `ACP generator formatting command ${ this . command } exited with code ${ this . exitCode } for ${ this . generatedDir } .` ;
93110 }
94111}
95112
@@ -157,7 +174,7 @@ export const downloadFile = Effect.fn("downloadFile")(function* (url: string, ou
157174 Effect . mapError (
158175 ( cause ) =>
159176 new AcpGeneratorDownloadFileError ( {
160- url,
177+ ... urlDiagnosticFields ( url ) ,
161178 outputPath,
162179 stage : "create-directory" ,
163180 cause,
@@ -168,14 +185,20 @@ export const downloadFile = Effect.fn("downloadFile")(function* (url: string, ou
168185 const response = yield * HttpClient . get ( url ) . pipe (
169186 Effect . flatMap ( HttpClientResponse . filterStatusOk ) ,
170187 Effect . mapError (
171- ( cause ) => new AcpGeneratorDownloadError ( { url, outputPath, stage : "request" , cause } ) ,
188+ ( cause ) =>
189+ new AcpGeneratorDownloadError ( {
190+ ...urlDiagnosticFields ( url ) ,
191+ outputPath,
192+ stage : "request" ,
193+ cause,
194+ } ) ,
172195 ) ,
173196 ) ;
174197 const text = yield * response . text . pipe (
175198 Effect . mapError (
176199 ( cause ) =>
177200 new AcpGeneratorDownloadError ( {
178- url,
201+ ... urlDiagnosticFields ( url ) ,
179202 outputPath,
180203 stage : "read-response" ,
181204 cause,
@@ -187,7 +210,7 @@ export const downloadFile = Effect.fn("downloadFile")(function* (url: string, ou
187210 Effect . mapError (
188211 ( cause ) =>
189212 new AcpGeneratorDownloadFileError ( {
190- url,
213+ ... urlDiagnosticFields ( url ) ,
191214 outputPath,
192215 stage : "write-file" ,
193216 cause,
@@ -250,7 +273,7 @@ export const formatGeneratedFiles = Effect.fn("formatGeneratedFiles")(function*
250273 new AcpGeneratorFormatProcessError ( {
251274 stage : "spawn" ,
252275 command,
253- args,
276+ argumentCount : args . length ,
254277 generatedDir,
255278 cause,
256279 } ) ,
@@ -262,7 +285,7 @@ export const formatGeneratedFiles = Effect.fn("formatGeneratedFiles")(function*
262285 new AcpGeneratorFormatProcessError ( {
263286 stage : "wait-for-exit" ,
264287 command,
265- args,
288+ argumentCount : args . length ,
266289 generatedDir,
267290 cause,
268291 } ) ,
@@ -272,7 +295,7 @@ export const formatGeneratedFiles = Effect.fn("formatGeneratedFiles")(function*
272295 if ( exitCode !== 0 ) {
273296 return yield * new AcpGeneratorFormatExitError ( {
274297 command,
275- args,
298+ argumentCount : args . length ,
276299 generatedDir,
277300 exitCode,
278301 } ) ;
0 commit comments