From dc8a9ae114f931a4812b9161aef59f2e0a559286 Mon Sep 17 00:00:00 2001 From: Maxime Jacquemin <maxime.jacquemin@cea.fr> Date: Wed, 13 Oct 2021 17:45:06 +0200 Subject: [PATCH] [ivette] Linter and error handling Maybe we could factorize the code that read a file with the one from the SourceCode component, as they look exactly the same. --- ivette/src/frama-c/plugins/eva/valueinfos.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ivette/src/frama-c/plugins/eva/valueinfos.tsx b/ivette/src/frama-c/plugins/eva/valueinfos.tsx index 8644eb31361..b538920a117 100644 --- a/ivette/src/frama-c/plugins/eva/valueinfos.tsx +++ b/ivette/src/frama-c/plugins/eva/valueinfos.tsx @@ -39,6 +39,12 @@ import { EvaAlarm } from './cells'; import { Callsite } from './stacks'; import { useModel } from './model'; +// -------------------------------------------------------------------------- +// --- Pretty Printing (Browser Console) +// -------------------------------------------------------------------------- + +const D = new Dome.Debug('Source Code'); + // -------------------------------------------------------------------------- // --- Stmt Printer // -------------------------------------------------------------------------- @@ -55,11 +61,13 @@ export function Stmt(props: StmtProps) { const markersInfo = States.useSyncArray(Ast.markerInfo); const line = markersInfo.getData(marker)?.sloc?.line; const file = markersInfo.getData(marker)?.sloc?.file; - const read = () => file ? readFile(file) : Promise.reject(); - const text = React.useMemo(read, [file]); + const errorMsg = () => { D.error(`Fail to load source code file ${file}`); }; + const onError = () => { if (file) errorMsg(); return ''; }; + const read = () => (file ? readFile(file).catch(onError) : Promise.reject()); + const text = React.useMemo(read, [file, onError]); const { result } = Dome.usePromise(text); const allLines = result?.split(/\r\n|\n/); - const title = allLines ? (line ? `Stmt: ${allLines[line - 1]}` : '') : '' ; + const title = allLines ? (line ? `Stmt: ${allLines[line - 1]}` : '') : ''; if (rank === undefined || !stmt) return null; // const title = `Stmt at global rank ${rank} (internal id: ${stmt})`; return ( -- GitLab