Browse Source

Add export on init crash + make error selectable

master
Gaëtan Renaudeau 7 years ago
parent
commit
94ce20cff0
  1. 2
      src/components/AppError.js
  2. 23
      src/components/ExportLogsBtn.js
  3. 39
      src/components/RenderError.js

2
src/components/AppError.js

@ -13,7 +13,7 @@ import RenderError from './RenderError'
const App = ({ language, error }: { error: Error, language: string }) => ( const App = ({ language, error }: { error: Error, language: string }) => (
<I18nextProvider i18n={i18n} initialLanguage={language}> <I18nextProvider i18n={i18n} initialLanguage={language}>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<RenderError disableExport error={error}> <RenderError withoutAppData error={error}>
<TriggerAppReady /> <TriggerAppReady />
</RenderError> </RenderError>
</ThemeProvider> </ThemeProvider>

23
src/components/ExportLogsBtn.js

@ -19,15 +19,24 @@ const mapStateToProps = createStructuredSelector({
class ExportLogsBtn extends Component<{ class ExportLogsBtn extends Component<{
t: *, t: *,
settings: *, settings: ?*,
accounts: *, accounts: ?*,
hookToShortcut?: boolean, hookToShortcut?: boolean,
}> { }> {
handleExportLogs = () => { handleExportLogs = () => {
const { accounts, settings } = this.props const { accounts, settings } = this.props
const logs = logger.exportLogs() const logs = logger.exportLogs()
const resourceUsage = webFrame.getResourceUsage() const resourceUsage = webFrame.getResourceUsage()
const report = { resourceUsage, logs, accounts, settings, date: new Date() } const report = {
resourceUsage,
logs,
accounts,
settings,
date: new Date(),
release: __APP_VERSION__,
git_commit: __GIT_REVISION__,
environment: __DEV__ ? 'development' : 'production',
}
console.log(report) // eslint-disable-line no-console console.log(report) // eslint-disable-line no-console
const reportJSON = JSON.stringify(report) const reportJSON = JSON.stringify(report)
const path = remote.dialog.showSaveDialog({ const path = remote.dialog.showSaveDialog({
@ -69,4 +78,10 @@ class ExportLogsBtn extends Component<{
} }
} }
export default translate()(connect(mapStateToProps)(ExportLogsBtn)) const WithAppData = connect(mapStateToProps)(ExportLogsBtn)
const WithoutAppData = ExportLogsBtn
const ExportLogsBtnDispatcher = ({ withAppData, ...rest }: *) =>
withAppData ? <WithAppData {...rest} /> : <WithoutAppData {...rest} />
export default translate()(ExportLogsBtnDispatcher)

39
src/components/RenderError.js

@ -1,6 +1,7 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import styled from 'styled-components'
import { shell, remote } from 'electron' import { shell, remote } from 'electron'
import qs from 'querystring' import qs from 'querystring'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
@ -21,7 +22,7 @@ import { IconWrapperCircle } from './SettingsPage/sections/Profile'
type Props = { type Props = {
error: Error, error: Error,
t: T, t: T,
disableExport?: boolean, withoutAppData?: boolean,
children?: *, children?: *,
} }
@ -75,7 +76,7 @@ ${error.stack}
} }
render() { render() {
const { error, t, disableExport, children } = this.props const { error, t, withoutAppData, children } = this.props
const { isHardResetting, isHardResetModalOpened } = this.state const { isHardResetting, isHardResetModalOpened } = this.state
return ( return (
<Box align="center" grow> <Box align="center" grow>
@ -100,7 +101,7 @@ ${error.stack}
<Button primary onClick={this.handleRestart}> <Button primary onClick={this.handleRestart}>
{t('app:crash.restart')} {t('app:crash.restart')}
</Button> </Button>
{!disableExport ? <ExportLogsBtn /> : null} <ExportLogsBtn withoutAppData={withoutAppData} />
<Button primary onClick={this.handleCreateIssue}> <Button primary onClick={this.handleCreateIssue}>
{t('app:crash.createTicket')} {t('app:crash.createTicket')}
</Button> </Button>
@ -120,10 +121,8 @@ ${error.stack}
renderIcon={this.hardResetIconRender} renderIcon={this.hardResetIconRender}
/> />
<Box my={6}> <Box my={6}>
<ErrContainer> <ErrContainer>{`${String(error)}
<strong>{String(error)}</strong> ${error.stack || 'no stacktrace'}`}</ErrContainer>
<div>{error.stack || 'no stacktrace'}</div>
</ErrContainer>
</Box> </Box>
<pre <pre
style={{ style={{
@ -142,21 +141,15 @@ ${error.stack}
} }
} }
const ErrContainer = ({ children }: { children: any }) => ( const ErrContainer = styled.pre`
<pre margin: auto;
style={{ max-width: 80vw;
margin: 'auto', overflow: auto;
maxWidth: '80vw', font-size: 10px;
overflow: 'auto', font-family: monospace;
fontSize: 10, cursor: text;
fontFamily: 'monospace', user-select: text;
cursor: 'text', opacity: 0.3;
userSelect: 'text', `
opacity: 0.3,
}}
>
{children}
</pre>
)
export default translate()(RenderError) export default translate()(RenderError)

Loading…
Cancel
Save