better error reporting

This commit is contained in:
Florian Dold 2016-11-19 16:33:29 +01:00
parent 50090b5fb4
commit 2cd4a85ed4
11 changed files with 54 additions and 95 deletions

View File

@ -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 {

View File

@ -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);
});

View File

@ -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 {

View File

@ -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>

View File

@ -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,

View File

@ -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 {

View File

@ -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>
);

View File

@ -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 {

View File

@ -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>

View File

@ -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: "" });

View File

@ -16,23 +16,24 @@
"src/checkable.ts",
"decl/lib.es6.d.ts",
"src/chromeBadge.ts",
"src/cryptoApi-test.ts",
"decl/urijs/URIjs.d.ts",
"src/cryptoApi-test.ts",
"src/components.ts",
"src/emscriptif-test.ts",
"decl/systemjs/systemjs.d.ts",
"src/emscriptif-test.ts",
"src/cryptoApi.ts",
"src/helpers-test.ts",
"decl/react-global.d.ts",
"src/helpers-test.ts",
"src/cryptoLib.ts",
"src/types-test.ts",
"decl/chrome/chrome.d.ts",
"src/wallet-test.ts",
"src/cryptoWorker.ts",
"src/wallet-test.ts",
"src/emscriptif.ts",
"src/helpers.ts",
"src/http.ts",
"src/logging.ts",
"src/moduleTrampoline.ts",
"src/query.ts",
"src/taler-wallet-lib.ts",
"src/types.ts",