From b9d20f1868610caa8b62e028b6c4b26f4e1d7c83 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 4 Feb 2020 16:20:16 +0000 Subject: [PATCH] Share plugin: Improve startup error handling --- plugins/tiddlywiki/share/rawmarkup.js | 32 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/plugins/tiddlywiki/share/rawmarkup.js b/plugins/tiddlywiki/share/rawmarkup.js index b604e5c17..697e949ed 100644 --- a/plugins/tiddlywiki/share/rawmarkup.js +++ b/plugins/tiddlywiki/share/rawmarkup.js @@ -15,20 +15,28 @@ Read tiddlers from the browser location hash // Get the hash var rawHash = document.location.hash.substring(1); if(rawHash.charAt(0) === "#") { - var hash = decodeURIComponent(rawHash.substring(1)); - // Try to parse the hash as JSON - var tiddlers; - try { - tiddlers= JSON.parse(hash); + var hash; + try{ + hash = decodeURIComponent(rawHash.substring(1)); } catch(ex) { + console.log("Error decoding location hash",ex); } - if(tiddlers) { - // Need to initialise these because we run before bootprefix.js and boot.js - window.$tw = window.$tw || {}; - $tw.boot = $tw.boot || {}; - $tw.preloadTiddlers = $tw.preloadTiddlers || []; - // Load our tiddlers - $tw.preloadTiddlers = $tw.preloadTiddlers.concat(tiddlers); + // Try to parse the hash as JSON + if(hash) { + var tiddlers; + try { + tiddlers= JSON.parse(hash); + } catch(ex) { + console.log("Error parsing JSON from location hash",ex); + } + if(tiddlers) { + // Need to initialise these because we run before bootprefix.js and boot.js + window.$tw = window.$tw || {}; + $tw.boot = $tw.boot || {}; + $tw.preloadTiddlers = $tw.preloadTiddlers || []; + // Load our tiddlers + $tw.preloadTiddlers = $tw.preloadTiddlers.concat(tiddlers); + } } }