1
1
import path from 'path' ;
2
- import { infoOut } from '../cli' ;
2
+ import { infoOut , warningOut } from '../cli' ;
3
3
import Document from "vscode-db2i/src/language/sql/document" ;
4
4
import { ObjectRef , StatementType } from 'vscode-db2i/src/language/sql/types' ;
5
5
import { Logger } from '../logger' ;
@@ -16,6 +16,14 @@ const DEFAULT_BINDER_TARGET: ILEObject = { systemName: `$(APP_BNDDIR)`, type: `B
16
16
17
17
const TextRegex = / \% T E X T .* (? = \n | \* ) / gm
18
18
19
+ export interface ParserError {
20
+ filePath : string ;
21
+ content : string ;
22
+ ileObject : ILEObject ;
23
+ }
24
+
25
+ export type ParserErrorCallback = ( error : ParserError ) => void ;
26
+
19
27
export interface ILEObject {
20
28
systemName : string ;
21
29
longName ?: string ;
@@ -85,6 +93,7 @@ export class Targets {
85
93
86
94
private actionSuggestions : TargetSuggestions = { } ;
87
95
96
+ private parserErrorCallback : ParserErrorCallback | undefined ;
88
97
public logger : Logger ;
89
98
90
99
constructor ( private cwd : string , private fs : ReadFileSystem ) {
@@ -95,6 +104,10 @@ export class Targets {
95
104
return ignoredObjects ;
96
105
}
97
106
107
+ public setParserErrorCallback ( callback : ParserErrorCallback ) {
108
+ this . parserErrorCallback = callback ;
109
+ }
110
+
98
111
public getCwd ( ) {
99
112
return this . cwd ;
100
113
}
@@ -397,8 +410,6 @@ export class Targets {
397
410
this . logger . flush ( relative ) ;
398
411
}
399
412
400
- const ext = pathDetail . ext . substring ( 1 ) . toLowerCase ( ) ;
401
-
402
413
try {
403
414
const content = await this . fs . readFile ( filePath ) ;
404
415
@@ -427,13 +438,21 @@ export class Targets {
427
438
type : `warning`
428
439
} ) ;
429
440
430
- console . log ( relative ) ;
431
- console . log ( e ) ;
441
+ if ( this . parserErrorCallback ) {
442
+ this . parserErrorCallback ( {
443
+ filePath,
444
+ content : e . content ,
445
+ ileObject : { systemName : pathDetail . name , type : this . getObjectType ( relative , pathDetail . ext ) }
446
+ } ) ;
447
+
448
+ } else {
449
+ warningOut ( `Failed to parse file ${ filePath } !` ) ;
450
+ warningOut ( `Error: ${ e . message } ` ) ;
451
+ warningOut ( `Create a GitHub issue if this persists.` ) ;
452
+ }
432
453
433
454
success = false ;
434
455
}
435
-
436
- infoOut ( `` ) ;
437
456
} else {
438
457
success = false ;
439
458
}
0 commit comments