11#include  < cerrno> 
22#include  < cstdarg> 
3+ #include  < sstream> 
34
45#include  " debug_utils-inl.h" 
56#include  " node_errors.h" 
@@ -185,23 +186,29 @@ static std::string GetErrorSource(Isolate* isolate,
185186  return  buf + std::string (underline_buf, off);
186187}
187188
188- static  std::string FormatStackTrace (Isolate* isolate, Local<StackTrace> stack) {
189+ static  std::string FormatStackTrace (
190+     Isolate* isolate,
191+     Local<StackTrace> stack,
192+     StackTracePrefix prefix = StackTracePrefix::kAt ) {
189193  std::string result;
190194  for  (int  i = 0 ; i < stack->GetFrameCount (); i++) {
191195    Local<StackFrame> stack_frame = stack->GetFrame (isolate, i);
192196    node::Utf8Value fn_name_s (isolate, stack_frame->GetFunctionName ());
193197    node::Utf8Value script_name (isolate, stack_frame->GetScriptName ());
194198    const  int  line_number = stack_frame->GetLineNumber ();
195199    const  int  column = stack_frame->GetColumn ();
196- 
200+     std::string prefix_str = prefix == StackTracePrefix::kAt 
201+                                  ? "     at " 
202+                                  : std::to_string (i + 1 ) + " : "  ;
197203    if  (stack_frame->IsEval ()) {
198204      if  (stack_frame->GetScriptId () == Message::kNoScriptIdInfo ) {
199-         result += SPrintF ("     at  [eval]:%i:%i\n "  , line_number, column);
205+         result += SPrintF (" %s [eval]:%i:%i\n " , prefix_str , line_number, column);
200206      } else  {
201207        std::vector<char > buf (script_name.length () + 64 );
202208        snprintf (buf.data (),
203209                 buf.size (),
204-                  "     at [eval] (%s:%i:%i)\n "  ,
210+                  " %s[eval] (%s:%i:%i)\n "  ,
211+                  prefix_str.c_str (),
205212                 *script_name,
206213                 line_number,
207214                 column);
@@ -214,7 +221,8 @@ static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
214221      std::vector<char > buf (script_name.length () + 64 );
215222      snprintf (buf.data (),
216223               buf.size (),
217-                "     at %s:%i:%i\n "  ,
224+                " %s%s:%i:%i\n "  ,
225+                prefix_str.c_str (),
218226               *script_name,
219227               line_number,
220228               column);
@@ -223,7 +231,8 @@ static std::string FormatStackTrace(Isolate* isolate, Local<StackTrace> stack) {
223231      std::vector<char > buf (fn_name_s.length () + script_name.length () + 64 );
224232      snprintf (buf.data (),
225233               buf.size (),
226-                "     at %s (%s:%i:%i)\n "  ,
234+                " %s%s (%s:%i:%i)\n "  ,
235+                prefix_str.c_str (),
227236               *fn_name_s,
228237               *script_name,
229238               line_number,
@@ -239,8 +248,10 @@ static void PrintToStderrAndFlush(const std::string& str) {
239248  fflush (stderr);
240249}
241250
242- void  PrintStackTrace (Isolate* isolate, Local<StackTrace> stack) {
243-   PrintToStderrAndFlush (FormatStackTrace (isolate, stack));
251+ void  PrintStackTrace (Isolate* isolate,
252+                      Local<StackTrace> stack,
253+                      StackTracePrefix prefix) {
254+   PrintToStderrAndFlush (FormatStackTrace (isolate, stack, prefix));
244255}
245256
246257std::string FormatCaughtException (Isolate* isolate,
@@ -329,7 +340,8 @@ void AppendExceptionLine(Environment* env,
329340}
330341
331342[[noreturn]] void  Abort () {
332-   DumpBacktrace (stderr);
343+   DumpNativeBacktrace (stderr);
344+   DumpJavaScriptBacktrace (stderr);
333345  fflush (stderr);
334346  ABORT_NO_BACKTRACE ();
335347}
@@ -338,14 +350,15 @@ void AppendExceptionLine(Environment* env,
338350  std::string name = GetHumanReadableProcessName ();
339351
340352  fprintf (stderr,
341-           " %s: %s:%s%s Assertion `%s' failed.\n "  ,
353+           " \n " 
354+           "   #  %s: %s at %s\n " 
355+           "   #  Assertion failed: %s\n\n "  ,
342356          name.c_str (),
343-           info.file_line ,
344-           info.function ,
345-           *info.function  ? " :"   : " "  ,
357+           info.function  ? info.function  : " (unknown function)"  ,
358+           info.file_line  ? info.file_line  : " (unknown source location)"  ,
346359          info.message );
347-   fflush (stderr);
348360
361+   fflush (stderr);
349362  Abort ();
350363}
351364
0 commit comments