Skip to content

Commit

Permalink
Merge pull request #67 from Strilanc/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Strilanc committed Apr 30, 2016
2 parents bce8066 + 9831f23 commit 2b39818
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
16 changes: 8 additions & 8 deletions res/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
<link rel="shortcut icon" href="favicon.ico">
</head>
<body style="margin: 0">
<a href="https://github.com/Strilanc/Quirk/"
style="position: fixed; bottom: 5px; right: 5px; font-size: 20px;">About Quirk</a>
<div id="inspectorDiv">
<div id="canvasDiv" style="width: 100%;">
<canvas id="drawCanvas"></canvas>
</div>
</div>
<div id="errorDiv" style="display:none; font-size:24px; font-family:monospace; color:red; background-color:#FFA;">
<div id="errorDiv" style="display:none; font-size:24px; font-family:monospace; color:red;">
An error happened. :(
<div id="errorMessageDiv" style="font-size: 16px;"></div>
<br/>
<br/>
You can:
<ul>
Please report it:
<ul style="font-size: 18px;">
<li>
<a id="error-github-anchor">Create an issue on github</a>
(requires an account)
(repository: <a href="https://github.com/Strilanc/Quirk">Strilanc/Quirk</a>)
</li>
<li>
Undo what you just did to the circuit (hit CTRL+Z).
</li>
<li>
<a id="error-mailto-anchor"></a>
</li>
</ul>
Useful details to mention:
<br/>
<br/>
Useful details to mention (auto-included if you use the create/email links above):
<br/>
<div id="errorDescDiv" style="font-size: 16px;"></div>
</div>
<script src="src.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/CircuitStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class CircuitStats {
return CircuitStats._fromCircuitAtTime_noFallback(circuitDefinition, time);
} catch (ex) {
notifyAboutRecoveryFromUnexpectedError(
"Computing circuit values failed. Defaulted to NaN results.",
`Defaulted to NaN results. Computing circuit values failed.`,
{circuitDefinition: Serializer.toJson(circuitDefinition)},
ex);
return new CircuitStats(
Expand Down
19 changes: 16 additions & 3 deletions src/fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@ import describe from "src/base/Describe.js"

let _alreadySeen = [];
let showErrorDiv = (subject, body) => {
let errDivStyle = document.getElementById('errorDiv').style;
if (errDivStyle.opacity < 0.7) {
// Partially faded away as user interacted with circuit.
// Enough time to justify updating the message despite the risk of clearing the user's selection.
_alreadySeen = [];
}

// Error just happened, so this should be showing and highlighted.
errDivStyle.backgroundColor = '#FFA';
errDivStyle.opacity = 1.0;
errDivStyle.display = 'block';

if (_alreadySeen.indexOf(body) !== -1) {
return;
}
_alreadySeen.push(body);

document.getElementById('errorDiv').style.display = 'block';
// Set shown error details.
document.getElementById('errorMessageDiv').innerText = subject;
document.getElementById('errorDescDiv').innerText = body;
document.getElementById('error-mailto-anchor').innerText = 'Email the issue to [email protected]';
document.getElementById('error-mailto-anchor').href = [
Expand Down Expand Up @@ -54,10 +67,10 @@ let notifyAboutRecoveryFromUnexpectedError = (recovery, context, error) => {
simplifySrcUrls(location)
].join('\n');

showErrorDiv(recovery, msg);
showErrorDiv(recovery + ' (' + (error.message || '') + ')', msg);
};

let simplifySrcUrls = textContainingUrls => textContainingUrls.replace(/http.+\/src\.min\.js/g, 'src.min.js');
let simplifySrcUrls = textContainingUrls => textContainingUrls.replace(/http.+?\/src\.min\.js/g, 'src.min.js');

let drawErrorBox = msg => {
let canvas = document.getElementById("drawCanvas");
Expand Down
7 changes: 7 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ const redrawNow = () => {
let painter = new Painter(canvas);
let shown = syncArea(inspector).previewDrop();
if (!currentCircuitStatsCache.circuitDefinition.isEqualTo(shown.circuitWidget.circuitDefinition)) {
// Maybe this fresh new circuit isn't failing. Clear the error tint.
let errDivStyle = document.getElementById('errorDiv').style;
errDivStyle.opacity *= 0.9;
if (errDivStyle.opacity < 0.06) {
errDivStyle.display = 'None'
}

currentCircuitStatsCache =
new CycleCircuitStats(shown.circuitWidget.circuitDefinition, Config.TIME_CACHE_GRANULARITY);
}
Expand Down

0 comments on commit 2b39818

Please sign in to comment.