lnsocket

A minimal C library for connecting to the lightning network
git clone git://jb55.com/lnsocket
Log | Files | Refs | Submodules | README | LICENSE

error.c (916B)


      1 
      2 #include "error.h"
      3 
      4 #include <stdlib.h>
      5 #include <stdarg.h>
      6 
      7 int note_error_(struct errors *errs_, const char *fmt, ...)
      8 {
      9 	static char buf[512];
     10 	struct error err;
     11 	struct cursor *errs;
     12 	va_list ap;
     13 
     14 	errs = &errs_->cur;
     15 
     16 	if (errs_->enabled == 0)
     17 		return 0;
     18 
     19 	va_start(ap, fmt);
     20 	vsprintf(buf, fmt, ap);
     21 	va_end(ap);
     22 
     23 	err.msg = buf;
     24 
     25 	if (!cursor_push_error(errs, &err)) {
     26 		fprintf(stderr, "arena OOM when recording error, ");
     27 		fprintf(stderr, "errs->p at %ld, remaining %ld, strlen %ld\n",
     28 				errs->p - errs->start, errs->end - errs->p, strlen(buf));
     29 	}
     30 
     31 	return 0;
     32 }
     33 
     34 void print_error_backtrace(struct errors *errors)
     35 {
     36 	struct cursor errs;
     37 	struct error err;
     38 
     39 	copy_cursor(&errors->cur, &errs);
     40 	errs.p = errs.start;
     41 
     42 	while (errs.p < errors->cur.p) {
     43 		if (!cursor_pull_error(&errs, &err)) {
     44 			fprintf(stderr, "backtrace: couldn't pull error\n");
     45 			return;
     46 		}
     47 		fprintf(stderr, "%s\n", err.msg);
     48 	}
     49 }