Skip to content

Commit

Permalink
Merge pull request #124 from BalticAmadeus/123-parser-error-message-i…
Browse files Browse the repository at this point in the history
…mprovement

Added ParserLogger
  • Loading branch information
hjuknonis authored Dec 4, 2023
2 parents 1bdd89d + 4b2a058 commit be6f1f3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/services/parser/ParserLogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export class ParserLogger {
public static parserLogger: ParserLogger = new ParserLogger();
private static errors: string[] = [];

private constructor () {

}

public static logError(errorName: string, ...optionalParams: any[]) {
console.error(errorName, optionalParams);
ParserLogger.errors.push(errorName);
}

public static getErrors(): string[] {
return ParserLogger.errors;
}

public static resetErrors(): void {
ParserLogger.errors = [];
}

}
4 changes: 3 additions & 1 deletion src/services/parser/presentation/callTree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CallTree, ModuleDetails } from "../../../common/PresentationData";
import { ParserLogger } from "../ParserLogger";
import { ProfilerRawData } from "../profilerRawData";
import { CallTreeData } from "../raw/callTreeData";
import { TracingData } from "../raw/tracingData";
Expand All @@ -24,7 +25,8 @@ export function calculateCallTree(rawData: ProfilerRawData, moduleDetailList: Mo
let moduleDetails: ModuleDetails = moduleDetailList.find(({ moduleID }) => moduleID === node.ModuleID)!;

if (!moduleDetails) {
console.error(`Module with ID ${node.ModuleID} not found`);
ParserLogger.logError(`Module with ID ${node.ModuleID} not found`);

break;
}

Expand Down
5 changes: 3 additions & 2 deletions src/services/parser/presentation/calledModules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CalledModules, ModuleDetails } from "../../../common/PresentationData";
import { ParserLogger } from "../ParserLogger";
import { ProfilerRawData } from "../profilerRawData";

/**
Expand All @@ -21,13 +22,13 @@ export function calculateCalledModules(rawData: ProfilerRawData, moduleDetailLis
} else {
let callerModuleDetails: ModuleDetails = moduleDetailList.find(({ moduleID }) => moduleID === node.CallerID)!;
if (!callerModuleDetails) {
console.error(`Module with ID ${node.CallerID} not found`);
ParserLogger.logError(`Module with ID ${node.CallerID} not found`);
break;
}

let calleeModuleDetails: ModuleDetails = moduleDetailList.find(({ moduleID }) => moduleID === node.CalleeID)!;
if (!calleeModuleDetails) {
console.error(`Module with ID ${node.CalleeID} not found`);
ParserLogger.logError(`Module with ID ${node.CalleeID} not found`);
break;
}

Expand Down
7 changes: 7 additions & 0 deletions src/services/profilerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import { transformData } from './parser/presentationData';
import { PresentationData } from '../common/PresentationData';
import { collectData } from './finder/xRefParser';
import {findLinesWithFunction } from './finder/lineFinder';
import { ParserLogger } from './parser/ParserLogger';

export class ProfilerService {
public parse(fileName: string): PresentationData {
ParserLogger.resetErrors();

const readData = readFile(fileName);
const rawData = parseProfilerData(readData);
const transformedData = transformData(rawData);
return transformedData;
}

public getErrors(): string[] {
return ParserLogger.getErrors();
}

public parseXRef(fileName: string, procedureName: string) {
const readData = readFile(fileName);
const xRefInfo = collectData(readData, procedureName);
Expand Down
12 changes: 11 additions & 1 deletion src/webview/ProfilerViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export class ProfilerViewer {

const profilerService = new ProfilerService();

var dataString = profilerService.parse(filePath);
let dataString = profilerService.parse(filePath);

handleErrors(profilerService.getErrors());

this.panel?.webview.postMessage(dataString);

Expand Down Expand Up @@ -132,6 +134,14 @@ function getProcedureNames(moduleName: string) {
return xRefInfo;
}

function handleErrors(errors: string[]) {
if (errors.length > 0) {
errors.forEach((error) => {
vscode.window.showErrorMessage(error);
});
}
}

function replaceDots(input: string): string {
const lastIndex = input.lastIndexOf(".");

Expand Down

0 comments on commit be6f1f3

Please sign in to comment.