11import path from 'path' ;
2- import { infoOut } from '../cli' ;
2+ import { infoOut , warningOut } from '../cli' ;
33import Document from "vscode-db2i/src/language/sql/document" ;
44import { ObjectRef , StatementType } from 'vscode-db2i/src/language/sql/types' ;
55import { Logger } from '../logger' ;
@@ -16,6 +16,14 @@ const DEFAULT_BINDER_TARGET: ILEObject = { systemName: `$(APP_BNDDIR)`, type: `B
1616
1717const TextRegex = / \% T E X T .* (? = \n | \* ) / gm
1818
19+ export interface ParserError {
20+ filePath : string ;
21+ content : string ;
22+ ileObject : ILEObject ;
23+ }
24+
25+ export type ParserErrorCallback = ( error : ParserError ) => void ;
26+
1927export interface ILEObject {
2028 systemName : string ;
2129 longName ?: string ;
@@ -85,6 +93,7 @@ export class Targets {
8593
8694 private actionSuggestions : TargetSuggestions = { } ;
8795
96+ private parserErrorCallback : ParserErrorCallback | undefined ;
8897 public logger : Logger ;
8998
9099 constructor ( private cwd : string , private fs : ReadFileSystem ) {
@@ -95,6 +104,10 @@ export class Targets {
95104 return ignoredObjects ;
96105 }
97106
107+ public setParserErrorCallback ( callback : ParserErrorCallback ) {
108+ this . parserErrorCallback = callback ;
109+ }
110+
98111 public getCwd ( ) {
99112 return this . cwd ;
100113 }
@@ -397,8 +410,6 @@ export class Targets {
397410 this . logger . flush ( relative ) ;
398411 }
399412
400- const ext = pathDetail . ext . substring ( 1 ) . toLowerCase ( ) ;
401-
402413 try {
403414 const content = await this . fs . readFile ( filePath ) ;
404415
@@ -427,13 +438,21 @@ export class Targets {
427438 type : `warning`
428439 } ) ;
429440
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+ }
432453
433454 success = false ;
434455 }
435-
436- infoOut ( `` ) ;
437456 } else {
438457 success = false ;
439458 }
0 commit comments