more logging

This commit is contained in:
Moon Man 2024-01-28 11:57:08 -05:00
parent 5c4f45a0dc
commit 9ae7e46855
4 changed files with 8 additions and 8 deletions

4
dist/bert.js vendored
View File

@ -93,11 +93,11 @@ export class Bert {
};
decode = (buffer) => {
if (buffer[0] !== Types.BERT_START) {
throw new Error("Not a valid BERT");
throw new Error("Invalid BERT start magic");
}
const obj = this.#decode(buffer.subarray(1));
if (obj.rest.length !== 0) {
throw new Error("Invalid BERT");
throw new Error(`Invalid BERT, remainder was: ${obj.rest.length}`);
}
return obj.value;
};

4
dist/main.js vendored
View File

@ -17,7 +17,7 @@ export class Port extends Duplex {
const lenBytes = process.stdin.read(4);
if (lenBytes) {
const termLen = this.bert.bytesToInt(lenBytes, 4, true);
process.stderr.write(`Got term length: ${termLen}\n`);
process.stderr.write(`Got incoming term length: ${termLen}\n`);
const termBytes = process.stdin.read(termLen);
if (termBytes) {
const decoded = this.bert.decode(termBytes);
@ -25,7 +25,7 @@ export class Port extends Duplex {
return decoded;
}
else {
process.stderr.write(`Read should have gotten ${termLen} bytes.\n`);
process.stderr.write(`Term read got erroneous null.\n`);
return null;
}
}

View File

@ -112,13 +112,13 @@ export class Bert {
decode = (buffer: Buffer) => {
if (buffer[0] !== Types.BERT_START) {
throw new Error("Not a valid BERT");
throw new Error("Invalid BERT start magic");
}
const obj = this.#decode(buffer.subarray(1));
if (obj.rest.length !== 0) {
throw new Error("Invalid BERT");
throw new Error(`Invalid BERT, remainder was: ${obj.rest.length}`);
}
return obj.value;

View File

@ -22,7 +22,7 @@ export class Port extends Duplex {
const lenBytes = process.stdin.read(4);
if (lenBytes) {
const termLen = this.bert.bytesToInt(lenBytes, 4, true);
process.stderr.write(`Got term length: ${termLen}\n`);
process.stderr.write(`Got incoming term length: ${termLen}\n`);
const termBytes = process.stdin.read(termLen);
if (termBytes) {
@ -31,7 +31,7 @@ export class Port extends Duplex {
return decoded;
}
else {
process.stderr.write(`Read should have gotten ${termLen} bytes.\n`);
process.stderr.write(`Term read got erroneous null.\n`);
return null;
}
}