From 2cd4a85ed4c57a705e3aeb88052be616e0461187 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sat, 19 Nov 2016 16:33:29 +0100 Subject: better error reporting --- src/logging.ts | 30 +++++++++++--- src/module-trampoline.js | 73 ----------------------------------- src/pages/confirm-contract.html | 2 +- src/pages/confirm-create-reserve.html | 2 +- src/pages/confirm-create-reserve.tsx | 24 ++++++++---- src/pages/logs.html | 2 +- src/pages/logs.tsx | 1 + src/pages/tree.html | 2 +- src/popup/popup.html | 2 +- src/wxBackend.ts | 2 +- tsconfig.json | 9 +++-- 11 files changed, 54 insertions(+), 95 deletions(-) delete mode 100644 src/module-trampoline.js diff --git a/src/logging.ts b/src/logging.ts index ff0987396..788a7df55 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -42,7 +42,7 @@ function makeDebug() { export async function log(msg: string, level: Level = "info"): Promise { let ci = getCallInfo(2); - return record(level, msg, ci.file, ci.line, ci.column); + return record(level, msg, undefined, ci.file, ci.line, ci.column); } function getCallInfo(level: number) { @@ -113,9 +113,10 @@ export interface LogEntry { timestamp: number; level: string; msg: string; - source: string|undefined; - col: number|undefined; - line: number|undefined; + detail?: string; + source?: string; + col?: number; + line?: number; id?: number; } @@ -133,7 +134,25 @@ export async function getLogs(): Promise { */ let barrier: any; -export async function record(level: Level, msg: string, source?: string, line?: number, col?: number): Promise { +export async function recordException(msg: string, e: any): Promise { + let stack: string|undefined; + let frame: Frame|undefined; + try { + stack = e.stack; + if (stack) { + let lines = stack.split("\n"); + frame = parseStackLine(lines[1]); + } + } catch (e) { + // ignore + } + if (!frame) { + frame = unknownFrame; + } + return record("error", e.toString(), stack, frame.file, frame.line, frame.column); +} + +export async function record(level: Level, msg: string, detail?: string, source?: string, line?: number, col?: number): Promise { if (typeof indexedDB === "undefined") { return; } @@ -166,6 +185,7 @@ export async function record(level: Level, msg: string, source?: string, line?: source, line, col, + detail, }; await new QueryRoot(db).put(logsStore, entry); } finally { diff --git a/src/module-trampoline.js b/src/module-trampoline.js deleted file mode 100644 index 20ed91638..000000000 --- a/src/module-trampoline.js +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is part of TALER - (C) 2016 GNUnet e.V. - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see - */ - - -/** - * Boilerplate to initialize the module system and call main() - * - * @author Florian Dold - */ - -"use strict"; - -if (typeof System === "undefined") { - throw Error("system loader not present (must be included before the" + - " trampoline"); -} - -System.config({ - defaultJSExtensions: true, - map: { - src: "/src/", - }, -}); - -let me = window.location.protocol - + "//" + window.location.host - + window.location.pathname.replace(/[.]html$/, ".js"); - -let domLoaded = false; - -document.addEventListener("DOMContentLoaded", function(event) { - domLoaded = true; -}); - -function execMain(m) { - if (m.main) { - console.log("executing module main"); - let res = m.main(); - } else { - console.warn("module does not export a main() function"); - } -} - -console.log("loading", me); - -System.import(me) - .then((m) => { - console.log("module imported", me); - if (domLoaded) { - execMain(m); - return; - } - document.addEventListener("DOMContentLoaded", function(event) { - execMain(m); - }); - }) - .catch((e) => { - console.log("trampoline failed"); - console.error(e.stack); - }); diff --git a/src/pages/confirm-contract.html b/src/pages/confirm-contract.html index 54a4d618d..261609d1c 100644 --- a/src/pages/confirm-contract.html +++ b/src/pages/confirm-contract.html @@ -16,7 +16,7 @@ - +