<commit_before>// @flow

import React, { Component } from 'react';
import styles from './ErrorBoundary.css';

type Props = {|
  children: React$Node,
|};

type State = {|
  callStack: string | null,
  componentStack: string | null,
  errorMessage: string | null,
  hasError: boolean,
|};

export default class ErrorBoundary extends Component<Props, State> {
  state: State = {
    callStack: null,
    componentStack: null,
    errorMessage: null,
    hasError: false,
  };

  componentDidCatch(error: any, { componentStack }: any) {
    const errorMessage =
      typeof error === 'object' && error.hasOwnProperty('message')
        ? error.message
        : error;

    const callStack =
      typeof error === 'object' && error.hasOwnProperty('stack')
        ? error.stack
            .split('\n')
            .slice(1)
            .join('\n')
        : null;

    this.setState({
      callStack,
      componentStack,
      errorMessage,
      hasError: true,
    });
  }

  render() {
    const { children } = this.props;
    const { callStack, componentStack, errorMessage, hasError } = this.state;

    let bugURL = process.env.GITHUB_URL;
    if (bugURL) {
      const title = `Error: "${errorMessage || ''}"`;
      const label = 'Component: Developer Tools';

      let body = '<!-- please provide repro information here -->\n';
      body += '\n---------------------------------------------';
      body += '\nPlease do not remove the text below this line';
      body += '\n---------------------------------------------';
      body += `\n\nDevTools version: ${process.env.DEVTOOLS_VERSION || ''}`;
      if (callStack) {
        body += `\n\nCall stack: ${callStack.trim()}`;
      }
      if (componentStack) {
        body += `\n\nComponent stack: ${componentStack.trim()}`;
      }

      bugURL += `/issues/new?labels=${encodeURI(label)}&title=${encodeURI(
        title
      )}&body=${encodeURI(body)}`;<commit_msg>Caps lock bug template request for repro steps :)<commit_after>// @flow

import React, { Component } from 'react';
import styles from './ErrorBoundary.css';

type Props = {|
  children: React$Node,
|};

type State = {|
  callStack: string | null,
  componentStack: string | null,
  errorMessage: string | null,
  hasError: boolean,
|};

export default class ErrorBoundary extends Component<Props, State> {
  state: State = {
    callStack: null,
    componentStack: null,
    errorMessage: null,
    hasError: false,
  };

  componentDidCatch(error: any, { componentStack }: any) {
    const errorMessage =
      typeof error === 'object' && error.hasOwnProperty('message')
        ? error.message
        : error;

    const callStack =
      typeof error === 'object' && error.hasOwnProperty('stack')
        ? error.stack
            .split('\n')
            .slice(1)
            .join('\n')
        : null;

    this.setState({
      callStack,
      componentStack,
      errorMessage,
      hasError: true,
    });
  }

  render() {
    const { children } = this.props;
    const { callStack, componentStack, errorMessage, hasError } = this.state;

    let bugURL = process.env.GITHUB_URL;
    if (bugURL) {
      const title = `Error: "${errorMessage || ''}"`;
      const label = 'Component: Developer Tools';

      let body = 'PLEASE INCLUDE REPRO INSTRUCTIONS AND EXAMPLE CODE\n';
      body += '\n---------------------------------------------';
      body += '\nPlease do not remove the text below this line';
      body += '\n---------------------------------------------';
      body += `\n\nDevTools version: ${process.env.DEVTOOLS_VERSION || ''}`;
      if (callStack) {
        body += `\n\nCall stack: ${callStack.trim()}`;
      }
      if (componentStack) {
        body += `\n\nComponent stack: ${componentStack.trim()}`;
      }

      bugURL += `/issues/new?labels=${encodeURI(label)}&title=${encodeURI(
        title
      )}&body=${encodeURI(body)}`;
{'fraction_non_alphanumeric': 0.18941717791411042, 'fraction_numerical': 0.0005112474437627812, 'mean_word_length': 2.189079054604727, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4422523', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1142, 'n_words': 288}