From 07b3f4fcf3e214b29c3a98c257efd08536925c0c Mon Sep 17 00:00:00 2001 From: worksofliam Date: Thu, 24 Jul 2025 09:08:29 -0400 Subject: [PATCH] Parser error callback Signed-off-by: worksofliam --- cli/src/targets/index.ts | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/cli/src/targets/index.ts b/cli/src/targets/index.ts index bfc1e48..14a8523 100644 --- a/cli/src/targets/index.ts +++ b/cli/src/targets/index.ts @@ -1,5 +1,5 @@ import path from 'path'; -import { infoOut } from '../cli'; +import { infoOut, warningOut } from '../cli'; import Document from "vscode-db2i/src/language/sql/document"; import { ObjectRef, StatementType } from 'vscode-db2i/src/language/sql/types'; import { Logger } from '../logger'; @@ -16,6 +16,14 @@ const DEFAULT_BINDER_TARGET: ILEObject = { systemName: `$(APP_BNDDIR)`, type: `B const TextRegex = /\%TEXT.*(?=\n|\*)/gm +export interface ParserError { + filePath: string; + content: string; + ileObject: ILEObject; +} + +export type ParserErrorCallback = (error: ParserError) => void; + export interface ILEObject { systemName: string; longName?: string; @@ -85,6 +93,7 @@ export class Targets { private actionSuggestions: TargetSuggestions = {}; + private parserErrorCallback: ParserErrorCallback | undefined; public logger: Logger; constructor(private cwd: string, private fs: ReadFileSystem) { @@ -95,6 +104,10 @@ export class Targets { return ignoredObjects; } + public setParserErrorCallback(callback: ParserErrorCallback) { + this.parserErrorCallback = callback; + } + public getCwd() { return this.cwd; } @@ -397,8 +410,6 @@ export class Targets { this.logger.flush(relative); } - const ext = pathDetail.ext.substring(1).toLowerCase(); - try { const content = await this.fs.readFile(filePath); @@ -427,13 +438,21 @@ export class Targets { type: `warning` }); - console.log(relative); - console.log(e); + if (this.parserErrorCallback) { + this.parserErrorCallback({ + filePath, + content: e.content, + ileObject: { systemName: pathDetail.name, type: this.getObjectType(relative, pathDetail.ext) } + }); + + } else { + warningOut(`Failed to parse file ${filePath}!`); + warningOut(`Error: ${e.message}`); + warningOut(`Create a GitHub issue if this persists.`); + } success = false; } - - infoOut(``); } else { success = false; }