Skip to content
Snippets Groups Projects
Commit dc8a9ae1 authored by Maxime Jacquemin's avatar Maxime Jacquemin Committed by David Bühler
Browse files

[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.
parent 4761976f
No related branches found
No related tags found
No related merge requests found
......@@ -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 (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment