2016-10-19 12:41:45 +00:00
|
|
|
import React from 'react'
|
2016-11-05 15:15:54 +00:00
|
|
|
import ansiHTML from 'ansi-html'
|
2016-10-19 12:41:45 +00:00
|
|
|
import Head from 'next/head'
|
2016-10-25 08:16:54 +00:00
|
|
|
import style from 'next/css'
|
2016-10-19 12:41:45 +00:00
|
|
|
|
|
|
|
export default class ErrorDebug extends React.Component {
|
|
|
|
static getInitialProps ({ err }) {
|
2016-11-24 14:03:16 +00:00
|
|
|
const { name, message, stack, module } = err
|
|
|
|
return { name, message, stack, path: module ? module.rawRequest : null }
|
2016-10-19 12:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-11-24 14:03:16 +00:00
|
|
|
const { name, message, stack, path } = this.props
|
2016-10-19 12:41:45 +00:00
|
|
|
|
2016-10-21 16:39:20 +00:00
|
|
|
return <div className={styles.errorDebug}>
|
2016-10-19 12:41:45 +00:00
|
|
|
<Head>
|
|
|
|
<style dangerouslySetInnerHTML={{ __html: `
|
|
|
|
body {
|
2016-11-05 15:15:54 +00:00
|
|
|
background: #a6004c;
|
2016-10-19 12:41:45 +00:00
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
`}} />
|
|
|
|
</Head>
|
2016-11-24 14:03:16 +00:00
|
|
|
{path ? <div className={styles.heading}>Error in {path}</div> : null}
|
|
|
|
{
|
|
|
|
name === 'ModuleBuildError'
|
|
|
|
? <pre className={styles.message} dangerouslySetInnerHTML={{ __html: ansiHTML(encodeHtml(message)) }} />
|
|
|
|
: <pre className={styles.message}>{stack}</pre>
|
|
|
|
}
|
2016-10-19 12:41:45 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-05 15:15:54 +00:00
|
|
|
const encodeHtml = str => {
|
|
|
|
return str.replace(/</g, '<').replace(/>/g, '>')
|
|
|
|
}
|
|
|
|
|
2016-10-21 16:39:20 +00:00
|
|
|
const styles = {
|
|
|
|
body: style({
|
2016-11-05 15:15:54 +00:00
|
|
|
background: '#a6004c',
|
2016-10-19 12:41:45 +00:00
|
|
|
margin: 0
|
2016-10-21 16:39:20 +00:00
|
|
|
}),
|
2016-10-19 12:41:45 +00:00
|
|
|
|
2016-10-21 16:39:20 +00:00
|
|
|
errorDebug: style({
|
2016-11-17 00:29:58 +00:00
|
|
|
height: '100vh',
|
2016-10-19 12:41:45 +00:00
|
|
|
padding: '16px',
|
2016-11-17 00:29:58 +00:00
|
|
|
boxSizing: 'border-box',
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
2016-10-21 16:39:20 +00:00
|
|
|
}),
|
2016-10-19 12:41:45 +00:00
|
|
|
|
2016-10-21 16:39:20 +00:00
|
|
|
message: style({
|
2016-10-30 06:07:18 +00:00
|
|
|
fontFamily: '"SF Mono", "Roboto Mono", "Fira Mono", menlo-regular, monospace',
|
2016-10-19 12:41:45 +00:00
|
|
|
fontSize: '10px',
|
2016-11-05 17:02:57 +00:00
|
|
|
color: '#fbe7f1',
|
2016-11-17 00:29:58 +00:00
|
|
|
margin: 0,
|
|
|
|
whiteSpace: 'pre-wrap',
|
|
|
|
wordWrap: 'break-word'
|
2016-10-21 16:39:20 +00:00
|
|
|
}),
|
2016-10-19 12:41:45 +00:00
|
|
|
|
2016-10-21 16:39:20 +00:00
|
|
|
heading: style({
|
2016-10-30 06:07:18 +00:00
|
|
|
fontFamily: '-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif',
|
2016-10-19 12:41:45 +00:00
|
|
|
fontSize: '13px',
|
|
|
|
fontWeight: 'bold',
|
2016-11-05 15:15:54 +00:00
|
|
|
color: '#ff84bf',
|
2016-10-19 12:41:45 +00:00
|
|
|
marginBottom: '20px'
|
2016-10-21 16:39:20 +00:00
|
|
|
})
|
|
|
|
}
|
2016-11-05 15:15:54 +00:00
|
|
|
|
2016-11-05 17:02:57 +00:00
|
|
|
// see color definitions of babel-code-frame:
|
|
|
|
// https://github.com/babel/babel/blob/master/packages/babel-code-frame/src/index.js
|
|
|
|
|
2016-11-05 15:15:54 +00:00
|
|
|
ansiHTML.setColors({
|
2016-11-14 17:31:42 +00:00
|
|
|
reset: ['fff', 'a6004c'],
|
2016-11-05 17:02:57 +00:00
|
|
|
darkgrey: 'e54590',
|
|
|
|
yellow: 'ee8cbb',
|
|
|
|
green: 'f2a2c7',
|
|
|
|
magenta: 'fbe7f1',
|
|
|
|
blue: 'fff',
|
|
|
|
cyan: 'ef8bb9',
|
|
|
|
red: 'fff'
|
2016-11-05 15:15:54 +00:00
|
|
|
})
|