diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index 9c1cf7af46..6e5f2edac1 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -48,22 +48,33 @@ function App() { plugin.internalEvents.on('circuit_compiling_done', (signalInputs: string[]) => { signalInputs = (signalInputs || []).filter(input => input) dispatch({ type: 'SET_SIGNAL_INPUTS', payload: signalInputs }) - compilerSuccess() + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) }) plugin.internalEvents.on('circuit_compiling_errored', compilerErrored) // r1cs events plugin.internalEvents.on('circuit_generating_r1cs_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'generating' })) - plugin.internalEvents.on('circuit_generating_r1cs_done', compilerSuccess) + plugin.internalEvents.on('circuit_generating_r1cs_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })) plugin.internalEvents.on('circuit_generating_r1cs_errored', compilerErrored) // witness events plugin.internalEvents.on('circuit_computing_witness_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'computing' })) - plugin.internalEvents.on('circuit_computing_witness_done', compilerSuccess) + plugin.internalEvents.on('circuit_computing_witness_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })) plugin.internalEvents.on('circuit_computing_witness_errored', compilerErrored) // parsing events - plugin.internalEvents.on('circuit_parsing_done', (_, filePathToId) => dispatch({ type: 'SET_FILE_PATH_TO_ID', payload: filePathToId })) + plugin.internalEvents.on('circuit_parsing_done', (_, filePathToId) => { + dispatch({ type: 'SET_FILE_PATH_TO_ID', payload: filePathToId }) + dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: null }) + }) + plugin.internalEvents.on('circuit_parsing_errored', (report) => { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' }) + dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: report }) + }) + plugin.internalEvents.on('circuit_parsing_warning', (report) => { + dispatch({ type: 'SET_COMPILER_STATUS', payload: 'warning' }) + dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: report }) + }) }, []) useEffect(() => { @@ -107,11 +118,6 @@ function App() { } } - const compilerSuccess = () => { - dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }) - dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: null }) - } - const value = { appState, dispatch, diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index dd957e6642..d5df548fe8 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -4,7 +4,7 @@ import EventManager from 'events' import pathModule from 'path' import { parse, compile, generate_witness, generate_r1cs, compiler_list } from 'circom_wasm' import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper' -import { CompilationConfig } from '../types' +import { CompilationConfig, CompilerReport } from '../types' export class CircomPluginClient extends PluginClient { public internalEvents: EventManager @@ -31,7 +31,7 @@ export class CircomPluginClient extends PluginClient { this.internalEvents.emit('circom_activated') } - async parse(path: string, fileContent?: string): Promise { + async parse(path: string, fileContent?: string): Promise { if (!fileContent) { // @ts-ignore fileContent = await this.call('fileManager', 'readFile', path) @@ -43,7 +43,7 @@ export class CircomPluginClient extends PluginClient { const parsedOutput = parse(path, this.lastParsedFiles) try { - const result = JSON.parse(parsedOutput) + const result: CompilerReport[] = JSON.parse(parsedOutput) if (result.length === 0) { // @ts-ignore @@ -96,25 +96,32 @@ export class CircomPluginClient extends PluginClient { await this.call('editor', 'clearErrorMarkers', [path]) } } + const mapFilePathToId = {} + const filePaths = Object.keys(this.lastParsedFiles) + + for (let index = 0; index < filePaths.length; index++) { + mapFilePathToId[index.toString()] = filePaths[index] + } + + this.internalEvents.emit('circuit_parsing_done', result, mapFilePathToId) + return result } catch (e) { - console.log(e) - } - const mapFilePathToId = {} - const filePaths = Object.keys(this.lastParsedFiles) - - for (let index = 0; index < filePaths.length; index++) { - mapFilePathToId[index.toString()] = filePaths[index] + throw new Error(e) } - - this.internalEvents.emit('circuit_parsing_done', parsedOutput, mapFilePathToId) - return parsedOutput } async compile(path: string, compilationConfig?: CompilationConfig): Promise { this.internalEvents.emit('circuit_compiling_start') const parseErrors = await this.parse(path) - if (parseErrors) throw new Error(parseErrors) + if (parseErrors && (parseErrors.length > 0)) { + if (parseErrors[0].type === 'Error') { + this.internalEvents.emit('circuit_parsing_errored', parseErrors) + return + } else if (parseErrors[0].type === 'Warning') { + this.internalEvents.emit('circuit_parsing_warning', parseErrors) + } + } if (compilationConfig) { const { prime, version } = compilationConfig @@ -211,7 +218,14 @@ export class CircomPluginClient extends PluginClient { this.internalEvents.emit('circuit_generating_r1cs_start') const parseErrors = await this.parse(path) - if (parseErrors) throw new Error(parseErrors) + if (parseErrors && (parseErrors.length > 0)) { + if (parseErrors[0].type === 'Error') { + this.internalEvents.emit('circuit_parsing_errored', parseErrors) + return + } else if (parseErrors[0].type === 'Warning') { + this.internalEvents.emit('circuit_parsing_warning', parseErrors) + } + } if (compilationConfig) { const { prime, version } = compilationConfig diff --git a/apps/circuit-compiler/src/app/types/index.ts b/apps/circuit-compiler/src/app/types/index.ts index aa83b383b4..b58d7a6322 100644 --- a/apps/circuit-compiler/src/app/types/index.ts +++ b/apps/circuit-compiler/src/app/types/index.ts @@ -2,7 +2,7 @@ import { compiler_list } from 'circom_wasm' import {Dispatch} from 'react' import { CircomPluginClient } from '../services/circomPluginClient' -export type CompilerStatus = "compiling" | "generating" | "computing" | "idle" | "errored" +export type CompilerStatus = "compiling" | "generating" | "computing" | "idle" | "errored" | "warning" export interface ICircuitAppContext { appState: AppState dispatch: Dispatch,