ref: 9b157a935a17079a2ca832ce95a2e29deeca1665
parent: 185c17074ef73c290e93a0bc85b3c7a92193d4d7
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Nov 20 17:32:52 EST 2023
tree: clean up errors a bit
--- a/fns.h
+++ b/fns.h
@@ -132,6 +132,11 @@
do{ \
if(debug) fprint(2, __VA_ARGS__); \
}while(0)
+#define fatal(...) \
+ do{ \
+ fprint(2, __VA_ARGS__); \
+ abort(); \
+ }while(0)
char* pack8(int*, char*, char*, uchar);
char* pack16(int*, char*, char*, ushort);
--- a/tree.c
+++ b/tree.c
@@ -386,15 +386,10 @@
d.muid = UNPACK32(p);
p += 4;
}
- if(p != m->v + m->nv){
- fprint(2, "kv=%P, m=%M\n", kv, m);
- fprint(2, "malformed stat message (op=%x, len=%lld, sz=%d)\n", op, p - m->v, m->nv);
- abort();
- }
- if(packdval(kv->v, kv->nv, &d) == nil){
- fprint(2, "repacking dir failed\n");
- abort();
- }
+ if(p != m->v + m->nv)
+ fatal("malformed stat: kv=%P, m=%M\n", kv, m);
+ if(packdval(kv->v, kv->nv, &d) == nil)
+ fatal("repacking dir failed\n");
}
static int
@@ -430,7 +425,7 @@
packtree(kv->v, kv->nv, &t);
return 1;
default:
- abort();
+ fatal("invalid op %d\n", m->op);
}
return 0;
}
@@ -500,10 +495,8 @@
*/
if(m.op == Oclearb || m.op == Oclobber)
ok = 0;
- else if(m.op != Oinsert){
- fprint(2, "%d(/%d), %d: %M not insert\n", i, b->nval, j, &m);
- abort();
- }
+ else if(m.op != Oinsert)
+ fatal("%d(/%d), %d: %M not insert\n", i, b->nval, j, &m);
cpkvp(&v, &m, buf, sizeof(buf));
spc -= valsz(&m);
goto Copy;
@@ -545,12 +538,8 @@
p->pullsz += msgsz(&m);
if(m.op == Oclearb || m.op == Oclobber)
continue;
- if(m.op != Oinsert){
- fprint(2, "%d(/%d), %d: %M not insert\n", i, b->nval, j, &m);
- showblk(2, up->b, "parent", 0);
- showblk(2, p->b, "current", 0);
- abort();
- }
+ if(m.op != Oinsert)
+ fatal("%d(/%d), %d: %M not insert\n", i, b->nval, j, &m);
while(pullmsg(up, j, &v, &m, &full, spc) == 0){
ok = apply(&v, &m, buf, sizeof(buf));
p->pullsz += msgsz(&m);
@@ -706,10 +695,8 @@
*/
if(m.op == Oclearb || m.op == Oclobber)
ok = 0;
- else if(m.op != Oinsert){
- fprint(2, "%d(/%d), %d: expected insert, got %M\n", i, b->nval, j, &m);
- abort();
- }
+ else if(m.op != Oinsert)
+ fatal("%d(/%d), %d: expected insert, got %M\n", i, b->nval, j, &m);
cpkvp(&v, &m, buf, sizeof(buf));
spc -= valsz(&m);
goto Copy;
@@ -1296,7 +1283,7 @@
else if(npath >2 && path[2].nl != nil)
dh = -1;
else
- abort();
+ fatal("broken path change");
assert(rb->bp.addr != 0);
@@ -1368,15 +1355,8 @@
j = bufsearch(p[i], k, &m, &same);
if(j < 0 || !same)
continue;
- if(!(ok || m.op == Oinsert)){
- fprint(2, "lookup %K << %M missing insert\n", k, &m);
- for(int j = 0; j < h; j++){
- fprint(2, "busted %d\n",j);
- if(p[j] != nil)
- showblk(2, p[j], "busted insert", 0);
- }
- abort();
- }
+ if(!(ok || m.op == Oinsert))
+ fatal("lookup %K << %M missing insert\n", k, &m);
ok = apply(r, &m, buf, nbuf);
for(j++; j < p[i]->nbuf; j++){
getmsg(p[i], j, &m);