From b9bded4a0e1834491528c0d7b76f1193d719f58b Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 14 Jan 2021 14:37:17 +0100 Subject: [PATCH] error management in debugger --- apps/remix-ide/src/app/tabs/debugger-tab.js | 1 + .../debugger-ui/src/lib/DebuggerAPI.ts | 65 ++++++++++++++++++ .../debugger-ui/src/lib/debugger-ui.css | 3 + .../debugger-ui/src/lib/debugger-ui.tsx | 66 +++++++++++++++---- .../src/lib/tx-browser/tx-browser.tsx | 31 +++++---- 5 files changed, 141 insertions(+), 25 deletions(-) create mode 100644 libs/remix-ui/debugger-ui/src/lib/DebuggerAPI.ts diff --git a/apps/remix-ide/src/app/tabs/debugger-tab.js b/apps/remix-ide/src/app/tabs/debugger-tab.js index 3b218fed58..edf7f39145 100644 --- a/apps/remix-ide/src/app/tabs/debugger-tab.js +++ b/apps/remix-ide/src/app/tabs/debugger-tab.js @@ -5,6 +5,7 @@ import { ViewPlugin } from '@remixproject/engine-web' import * as packageJson from '../../../../../package.json' import React from 'react' // eslint-disable-line import ReactDOM from 'react-dom' +import modalDialogCustom from '../ui/modal-dialog-custom' const yo = require('yo-yo') const css = require('./styles/debugger-tab-styles') diff --git a/libs/remix-ui/debugger-ui/src/lib/DebuggerAPI.ts b/libs/remix-ui/debugger-ui/src/lib/DebuggerAPI.ts new file mode 100644 index 0000000000..d9f8d10ff0 --- /dev/null +++ b/libs/remix-ui/debugger-ui/src/lib/DebuggerAPI.ts @@ -0,0 +1,65 @@ + +import type { CompilationResult, CompilationSource } from '@remix-project/remix-solidity-ts' + +export interface DebuggerUIProps { + debuggerAPI: DebuggerAPI +} + +interface EditorEvent { + event: { + register(eventName: 'breakpointCleared' | 'breakpointAdded' | 'contentChanged', + callback: (fileName: string, row: string | number) => void) + } +} + +interface LineColumnLocation { + start: { + line: number, column: number + }, + end: { + line: number, column: number + } +} + +interface RawLocation { + start: number, length: number +} + +interface Sources { + [fileName: string] : {content: string} +} + +interface CompilationOutput { + source: { sources: Sources, target: string } + data: CompilationResult + getSourceName: (id: number) => string +} + +interface Asts { + [fileName: string] : CompilationSource // ast +} + +interface TransactionReceipt { + blockHash: string + blockNumber: number + transactionHash: string + transactionIndex: number + from: string + to: string + contractAddress: string | null + } + +export interface DebuggerAPI { + offsetToLineColumnConverter: { offsetToLineColumn: (sourceLocation: RawLocation, file: number, contents: Sources, asts: Asts) => LineColumnLocation } + debugHash: string + debugHashRequest: string + removeHighlights: boolean + editor: EditorEvent + discardHighlight: () => void + highlight: (lineColumnPos: LineColumnLocation, path: string) => void + fetchContractAndCompile: (address: string, currentReceipt: TransactionReceipt) => CompilationOutput + getFile: (path: string) => string + setFile: (path: string, content: string) => void + getDebugWeb3: () => any // returns an instance of web3.js + showMessage: (title: string, message: string) => void +} \ No newline at end of file diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.css b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.css index 1bbc2026b1..7bb10333dc 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.css +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.css @@ -13,4 +13,7 @@ } .debuggerConfig label { margin: 0; +} +.validationError { + overflow-wrap: break-word; } \ No newline at end of file diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index 8b159744af..6a8833df73 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -26,7 +26,9 @@ export const DebuggerUI = (props: DebuggerUIProps) => { debugWithGeneratedSources: false }, toastMessage: '', - currentDebugTransaction: '' + currentDebugTransaction: '', + validationError: '', + txNumberIsEmpty: true }) useEffect(() => { @@ -85,7 +87,9 @@ export const DebuggerUI = (props: DebuggerUIProps) => { try { content = await debuggerModule.getFile(path) } catch (e) { - console.log('unable to fetch generated sources, the file probably doesn\'t exist yet', e) + const message = 'Unable to fetch generated sources, the file probably doesn\'t exist yet.' + debuggerModule.showMessage('Debugging error', message) + console.log(message, ' ', e) } if (content !== source.contents) { await debuggerModule.setFile(path, source.contents) @@ -108,6 +112,16 @@ export const DebuggerUI = (props: DebuggerUIProps) => { startDebugging(blockNumber, txNumber, tx) } + const updateTxNumberFlag = (empty: boolean) => { + setState(prevState => { + return { + ...prevState, + txNumberIsEmpty: empty, + validationError: '' + } + }) + } + const unloadRequested = (blockNumber, txIndex, tx) => { unLoad() } @@ -144,7 +158,19 @@ export const DebuggerUI = (props: DebuggerUIProps) => { } }) const web3 = await debuggerModule.getDebugWeb3() - const currentReceipt = await web3.eth.getTransactionReceipt(txNumber) + let currentReceipt + try { + currentReceipt = await web3.eth.getTransactionReceipt(txNumber) + } catch (e) { + setState(prevState => { + return { + ...prevState, + validationError: e.message + } + }) + console.log(e.message) + } + const debuggerInstance = new Debugger({ web3, offsetToLineColumnConverter: debuggerModule.offsetToLineColumnConverter, @@ -153,6 +179,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { const ret = await debuggerModule.fetchContractAndCompile(address, currentReceipt) return ret } catch (e) { + debuggerModule.showMessage('Debugging error', 'Unable to fetch a transaction.') console.error(e) } return null @@ -169,21 +196,33 @@ export const DebuggerUI = (props: DebuggerUIProps) => { debugging: true, currentReceipt, debugger: debuggerInstance, - toastMessage: `debugging ${txNumber}` + toastMessage: `debugging ${txNumber}`, + validationError: '' } }) }).catch((error) => { - setState(prevState => { - return { - ...prevState, - toastMessage: JSON.stringify(error) - } - }) + if (JSON.stringify(error) !== '{}') { + let message = 'Error: ' + JSON.stringify(error) + message = message.split(`\\"`).join(`'`) + setState(prevState => { + return { + ...prevState, + validationError: message + } + }) + console.log(message) + } unLoad() }) } const debug = (txHash) => { + setState(prevState => { + return { + ...prevState, + validationError: '' + } + }) startDebugging(null, txHash, null) } @@ -208,8 +247,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
-
-

Debugger Configuration

+
+

Debugger Configuration

{ setState(prevState => { @@ -218,8 +257,9 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }} type="checkbox" title="Debug with generated sources" />
+ { (state.validationError && !state.txNumberIsEmpty) && {state.validationError} }
- + { state.debugging && } { state.debugging && }
diff --git a/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx b/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx index 46b937f795..dd1b76030d 100644 --- a/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/tx-browser/tx-browser.tsx @@ -1,11 +1,12 @@ -import React, { useState, useEffect } from 'react' // eslint-disable-line +import React, { useState, useEffect, useRef } from 'react' import './tx-browser.css' -export const TxBrowser = ({ requestDebug, unloadRequested, transactionNumber, debugging }) => { +export const TxBrowser = ({ requestDebug, updateTxNumberFlag, unloadRequested, transactionNumber, debugging }) => { const [state, setState] = useState({ txNumber: '' }) + const inputValue = useRef(null) useEffect(() => { setState(prevState => { return { @@ -41,35 +42,41 @@ export const TxBrowser = ({ requestDebug, unloadRequested, transactionNumber, de }) } + const txInputOnInput = () => { + updateTxNumberFlag(!inputValue.current.value) + } + return ( -
-
-
+
+
+
txInputChanged(value)} + onInput={txInputOnInput} placeholder={'Transaction hash, should start with 0x'} - data-id="debuggerTransactionInput" + data-id='debuggerTransactionInput' disabled={debugging} />
-
+
- +
) }