diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-19 16:33:29 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-19 16:33:29 +0100 |
commit | 2cd4a85ed4c57a705e3aeb88052be616e0461187 (patch) | |
tree | 7adf45ccda4eace9d350cb593ae19cd1151d300e /src | |
parent | 50090b5fb44f9d3986064dfe9b6190b66cbe49bf (diff) | |
download | wallet-core-2cd4a85ed4c57a705e3aeb88052be616e0461187.tar.xz |
better error reporting
Diffstat (limited to 'src')
-rw-r--r-- | src/logging.ts | 30 | ||||
-rw-r--r-- | src/module-trampoline.js | 73 | ||||
-rw-r--r-- | src/pages/confirm-contract.html | 2 | ||||
-rw-r--r-- | src/pages/confirm-create-reserve.html | 2 | ||||
-rw-r--r-- | src/pages/confirm-create-reserve.tsx | 24 | ||||
-rw-r--r-- | src/pages/logs.html | 2 | ||||
-rw-r--r-- | src/pages/logs.tsx | 1 | ||||
-rw-r--r-- | src/pages/tree.html | 2 | ||||
-rw-r--r-- | src/popup/popup.html | 2 | ||||
-rw-r--r-- | src/wxBackend.ts | 2 |
10 files changed, 49 insertions, 91 deletions
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<void> { 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<LogEntry[]> { */ let barrier: any; -export async function record(level: Level, msg: string, source?: string, line?: number, col?: number): Promise<void> { +export async function recordException(msg: string, e: any): Promise<void> { + 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<void> { 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 <http://www.gnu.org/licenses/> - */ - - -/** - * 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 @@ <!-- <script src="/src/vendor/jed.js"></script> --> <script src="/src/i18n.js"></script> <script src="/src/i18n/strings.js"></script> - <script src="/src/module-trampoline.js"></script> + <script src="/src/moduleTrampoline.js"></script> <style> button.accept { diff --git a/src/pages/confirm-create-reserve.html b/src/pages/confirm-create-reserve.html index c67c7e960..b679de9c9 100644 --- a/src/pages/confirm-create-reserve.html +++ b/src/pages/confirm-create-reserve.html @@ -17,7 +17,7 @@ <!-- module loading --> <script src="/src/vendor/system-csp-production.src.js"></script> - <script src="/src/module-trampoline.js"></script> + <script src="/src/moduleTrampoline.js"></script> <style> diff --git a/src/pages/confirm-create-reserve.tsx b/src/pages/confirm-create-reserve.tsx index 963bd0697..81a90650c 100644 --- a/src/pages/confirm-create-reserve.tsx +++ b/src/pages/confirm-create-reserve.tsx @@ -374,14 +374,24 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { } export async function main() { - const url = URI(document.location.href); - const query: any = URI.parseQuery(url.query()); - const amount = AmountJson.checked(JSON.parse(query.amount)); - const callback_url = query.callback_url; - const bank_url = query.bank_url; - const wt_types = JSON.parse(query.wt_types); - try { + const url = URI(document.location.href); + const query: any = URI.parseQuery(url.query()); + let amount; + try { + amount = AmountJson.checked(JSON.parse(query.amount)); + } catch (e) { + throw Error(`Can't parse amount: ${e.message}`); + } + const callback_url = query.callback_url; + const bank_url = query.bank_url; + let wt_types; + try { + wt_types = JSON.parse(query.wt_types); + } catch (e) { + throw Error(`Can't parse wire_types: ${e.message}`); + } + const suggestedExchangeUrl = await getSuggestedExchange(amount.currency); let args = { wt_types, diff --git a/src/pages/logs.html b/src/pages/logs.html index 8d35bcbd7..9178298f8 100644 --- a/src/pages/logs.html +++ b/src/pages/logs.html @@ -19,7 +19,7 @@ <script src="/src/i18n/strings.js"></script> <script src="/src/vendor/system-csp-production.src.js"></script> - <script src="/src/module-trampoline.js"></script> + <script src="/src/moduleTrampoline.js"></script> <style> .tree-item { diff --git a/src/pages/logs.tsx b/src/pages/logs.tsx index 126659fe7..15bb3d270 100644 --- a/src/pages/logs.tsx +++ b/src/pages/logs.tsx @@ -38,6 +38,7 @@ class LogView extends React.Component<LogViewProps, void> { <li>file: {e.source || "(unknown)"}</li> <li>line: {e.line || "(unknown)"}</li> <li>col: {e.col || "(unknown)"}</li> + {(e.detail ? <li> detail: <pre>{e.detail}</pre></li> : [])} </ul> </div> ); diff --git a/src/pages/tree.html b/src/pages/tree.html index 306044159..4be7a5cdc 100644 --- a/src/pages/tree.html +++ b/src/pages/tree.html @@ -19,7 +19,7 @@ <script src="/src/i18n/strings.js"></script> <script src="/src/vendor/system-csp-production.src.js"></script> - <script src="/src/module-trampoline.js"></script> + <script src="/src/moduleTrampoline.js"></script> <style> .tree-item { diff --git a/src/popup/popup.html b/src/popup/popup.html index 30b11aaea..5800519a4 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -16,7 +16,7 @@ <script src="/src/i18n/strings.js"></script> <script src="/src/vendor/system-csp-production.src.js"></script> - <script src="/src/module-trampoline.js"></script> + <script src="/src/moduleTrampoline.js"></script> </head> <body> diff --git a/src/wxBackend.ts b/src/wxBackend.ts index ec6d95874..7893dd64d 100644 --- a/src/wxBackend.ts +++ b/src/wxBackend.ts @@ -425,7 +425,7 @@ function clearRateLimitCache() { export function wxMain() { window.onerror = (m, source, lineno, colno, error) => { - logging.record("error", m + error, source || "(unknown)", lineno || 0, colno || 0); + logging.record("error", m + error, undefined, source || "(unknown)", lineno || 0, colno || 0); } chrome.browserAction.setBadgeText({ text: "" }); |