/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ const errorRegexp = /^Error:?\s*$/ ; const removeBlankErrorLine = ( str ) => str . split ( '\n' ) . filter ( ( line ) => ! errorRegexp . test ( line ) ) . join ( '\n' ) . trimRight ( ) ; export const separateMessageFromStack = ( content ) : { message : string ; stack : string ; } => { if ( ! content ) { return { message : '' , stack : '' } ; } const messageMatch = content . match ( /^(?:Error: )?([\s\S]*?(?=\n\s*at\s.*:\d*:\d*)|\s*.*)([\s\S]*)$/ ) ; if ( ! messageMatch ) { throw new Error ( 'If you hit this error, the regex above is buggy.' ) ; } const message = removeBlankErrorLine ( messageMatch [ 1 ] ) ; const stack = removeBlankErrorLine ( messageMatch [ 2 ] ) ; return { message , stack } ; } ;