Skip to content

Commit

Permalink
Improved message structure
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Oct 22, 2024
1 parent 36e559d commit 9db402b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/core/compile/CompilationFilesResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class CompilationFilesResolver {
filteredResolvedFilesInfo = resolvedFilesInfoToCompile;
}

Reporter!.reportAllWarnings(spinnerId);
Reporter!.reportCircuitFilesResolvingResult(spinnerId);

const filteredSourceNamesToCompile: string[] = filteredResolvedFilesInfo.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class CircomTemplateInputsVisitor extends CircomVisitor<void> {
ctx.expression() instanceof BlockInstantiationExpressionContext ||
ctx.expression() instanceof DotExpressionContext
) {
Reporter?.reportUnsupportedExpression(ctx.expression().getText());
Reporter?.reportUnsupportedExpression(this._templateName, ctx.expression());

return [0n];
}
Expand Down
12 changes: 9 additions & 3 deletions src/reporter/ReporterFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import debug from "debug";
import { VerifierLanguageType } from "@solarity/zkit";

import { CircuitArtifact } from "../types/artifacts/circuit-artifacts";
import { CompilationInfo, CircuitSetupInfo } from "../types/core";
import { CompilationInfo, CircuitSetupInfo, SimpleParserRuleContext } from "../types/core";
import {
ProgressReporter,
CircuitFilesResolvingReporter,
Expand Down Expand Up @@ -222,8 +222,14 @@ class ReporterFacade {
this._progressReporter.updateProgressBarValue(valueToAdd);
}

public reportUnsupportedExpression(contextText: string) {
this._warningsReporter.reportUnsupportedExpression(contextText);
public reportUnsupportedExpression(templateName: string, context: SimpleParserRuleContext) {
this._warningsReporter.reportUnsupportedExpression(templateName, context);
}

public reportAllWarnings(spinnerId: string | null) {
if (!this._warningsReporter.hasWarnings()) return;

this._warningsReporter.reportAllWarnings(spinnerId);
}

public verboseLog(namespace: string, formatterStr: string, logArgs: any[] = []) {
Expand Down
10 changes: 10 additions & 0 deletions src/reporter/SpinnerProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export class BaseSpinnerProcessor {
this._idToSpinnerData.delete(spinnerId);
}

public warnSpinner(spinnerId: string, warningMessage: string) {
const spinnerData = this._idToSpinnerData.get(spinnerId);

if (!spinnerData) return;

spinnerData.spinner.warn(warningMessage);

this._idToSpinnerData.delete(spinnerId);
}

public getWorkingTime(spinnerId: string, fractionDigits: number = 2): string | undefined {
const spinnerData = this._idToSpinnerData.get(spinnerId);

Expand Down
39 changes: 36 additions & 3 deletions src/reporter/reporters/WarningsReporter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
import { SimpleParserRuleContext } from "../../types/core";

import { SpinnerProcessor } from "../../reporter";
import { BaseReporter } from "../../reporter/reporters/BaseReporter";

export class WarningsReporter extends BaseReporter {
public reportUnsupportedExpression(contextText: string) {
public warnings: Set<string> = new Set();

constructor(quiet: boolean) {
super(quiet);

this.warnings = new Set();
}

public reportUnsupportedExpression(templateName: string, context: SimpleParserRuleContext) {
if (this.isQuiet()) return;

console.warn(
`Expression structure: ${contextText} not supported if used to determine the dimension of an input signal!`,
this.warnings.add(
`Inside the ${templateName} circuit (${context.start.line}:${context.start.column})\r
\rThe expression structure: ${context.getText()} not supported if used to determine the dimension of an input signal!`,
);
}

public reportAllWarnings(spinnerId: string | null) {
if (this.isQuiet() || !spinnerId) return;

const resolvingTimeMessage: string = this._getSpinnerWorkingTimeMessage(
SpinnerProcessor!.getWorkingTime(spinnerId),
);

SpinnerProcessor!.warnSpinner(
spinnerId,
`Circuits are ready for the compilation ${resolvingTimeMessage}. But the analysis ended with warnings:`,
);

for (const warning of this.warnings) {
console.warn(warning);
}
}

public hasWarnings(): boolean {
return this.warnings.size > 0;
}
}
17 changes: 17 additions & 0 deletions src/types/core/dependencies/parser/circom-files-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ export type CircomFileData = {
mainComponentInfo: MainComponent;
templates: Templates;
};

export interface Token {
tokenIndex: number;
line: number;
column: number;
channel: number;
text: string;
type: number;
start: number;
stop: number;
}

export interface SimpleParserRuleContext {
start: Token;

getText(): string;
}

0 comments on commit 9db402b

Please sign in to comment.