This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
172 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ out | |
package-lock.json | ||
node_modules | ||
.DS_Store | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React, { Component } from 'react' | ||
|
||
import connect from '../Helpers/connect' | ||
|
||
import Modal from '../../Elements/Modal' | ||
|
||
import BugIcon from '../../Elements/icons/errorant.svg' | ||
|
||
import { sanitizeError, sanitizePaths } from '../Helpers/sanitize.js' | ||
|
||
import { shell } from 'electron' | ||
|
||
const { app } = require('electron').remote | ||
|
||
class BugModal extends Component { | ||
constructor () { | ||
super() | ||
this.scrollDedupeTimeout = null | ||
} | ||
|
||
// grabs the last 500 log lines as a string formatted for inclusion as a github issue | ||
renderAndSanitizeLogLines () { | ||
let result = '' | ||
if (this.props.logs && this.props.logs.lines && this.props.logs.lines.length > 0) { | ||
let maxLines = -175 // negative because Array.slice -- we want the last 175 lines, not the first 175 | ||
|
||
// GitHub has a max URL length of ~8KiB, so we truncate logs to fit within that | ||
while (encodeURIComponent(result = _getLastNLogLines(maxLines, this.props.logs)).length > 7500) { | ||
maxLines++ // reduces number of lines we get next time | ||
} | ||
} | ||
return sanitizePaths(result) | ||
} | ||
|
||
renderIssueBody(sanitizedSystemError, sanitizedLogLines) { | ||
let issueBody = | ||
"<!-- Please give us as much detail as you can about what you were doing at the time of the error, and any other relevant information -->\n" + | ||
"\n" + | ||
"\n" + | ||
`PLATFORM: ${process.platform}\n` + | ||
`GANACHE VERSION: ${app.getVersion()}\n` + | ||
"\n" + | ||
"EXCEPTION:\n" + | ||
"```\n" + | ||
`${sanitizedSystemError}\n` + | ||
"```" | ||
|
||
if (sanitizedLogLines) { | ||
issueBody += "\n" + | ||
"\n" + | ||
"APPLICATION LOG:\n" + | ||
"```\n" + | ||
`${sanitizedLogLines}\n` + | ||
"```" | ||
} | ||
return encodeURIComponent(issueBody).replace(/%09/g, '') | ||
} | ||
|
||
render () { | ||
let unsanitizedSystemError = this.props.systemError | ||
let sanitizedSystemError = '' | ||
let sanitizedLogLines = '' | ||
|
||
if (unsanitizedSystemError) { | ||
sanitizedSystemError = sanitizeError(unsanitizedSystemError) | ||
sanitizedLogLines = this.renderAndSanitizeLogLines() | ||
} | ||
|
||
return ( | ||
<Modal className="BugModal"> | ||
<section className="Bug"> | ||
<BugIcon /*size={192}*/ /> | ||
<h4>Uh Oh... That's a bug.</h4> | ||
<p> | ||
Ganache encountered an error. Help us fix it by raising a GitHub issue!<br /><br /> Mention the following error information when writing your ticket, and please include as much information as possible. Sorry about that! | ||
</p> | ||
<textarea disabled={true} value={sanitizedSystemError} /> | ||
<footer> | ||
<button | ||
onClick={() => { | ||
const title = encodeURIComponent( | ||
`System Error when running Ganache ${app.getVersion()} on ${process.platform}` | ||
) | ||
|
||
const body = this.renderIssueBody(sanitizedSystemError, sanitizedLogLines) | ||
|
||
shell.openExternal( | ||
`https://github.com/trufflesuite/ganache/issues/new?title=${title}&body=${body}` | ||
) | ||
}} | ||
> | ||
Raise Github Issue | ||
</button> | ||
<button | ||
onClick={() => { | ||
app.relaunch() | ||
app.exit() | ||
}} | ||
> | ||
RELAUNCH | ||
</button> | ||
</footer> | ||
</section> | ||
</Modal> | ||
) | ||
} | ||
} | ||
|
||
function _getLastNLogLines(maxLines, logs) { | ||
let firstLogTime = logs.lines[0].time.getTime() | ||
return logs.lines | ||
.slice(maxLines) | ||
.map(v => `T+${v.time.getTime() - firstLogTime}ms: ${v.line}`) | ||
.join('\n') | ||
} | ||
|
||
|
||
export default connect(BugModal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.Modal { | ||
&.BugModal { | ||
.Bug { | ||
textarea { | ||
min-height: 5rem; /* Overwrite Modal textarea styles */ | ||
max-height: 5rem; | ||
background-color: var(--app-button-primary-disabled-border-color); | ||
width: 100%; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
svg { | ||
width: 192px; | ||
height: 192px; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
const { app } = require('electron').remote | ||
|
||
// return a sanitized error string from an Error object or string which contains an error message | ||
export function sanitizeError(errorUnsanitized) { | ||
return sanitizePaths(errorUnsanitized.stack || errorUnsanitized) | ||
} | ||
|
||
// Remove any user-specific paths in exception messages | ||
export function sanitizePaths (message) { | ||
// Prepare our paths so we *always* will get a match no matter | ||
// path separator (oddly, on Windows, different errors will give | ||
// us different path separators) | ||
var appPath = app.getAppPath().replace(/\\/g, "/") | ||
|
||
// I couldn't figure out the regex, so a loop will do. | ||
while (message.indexOf(appPath) >= 0) { | ||
message = message.replace(appPath, "") | ||
} | ||
|
||
return message | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters