Skip to content

Commit 6bd69a2

Browse files
committed
lib: better assert messages
1 parent bf85983 commit 6bd69a2

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = exports = function (targetPath) {
5252
var volumePath = findVolume(targetPath, targetStat);
5353
var volumeStat = fs.statSync(volumePath);
5454

55-
assert(targetStat.isFile() || targetStat.isDirectory());
55+
assert(targetStat.isFile() || targetStat.isDirectory(), 'Target is a file or directory');
5656

5757
info.target = {
5858
id: targetStat.ino,
@@ -134,7 +134,7 @@ module.exports = exports = function (targetPath) {
134134
(function addType18() {
135135

136136
var vl = volumePath.length;
137-
assert(targetPath.slice(0, vl) === volumePath);
137+
assert.equal(targetPath.slice(0, vl), volumePath);
138138
var lp = targetPath.slice(vl);
139139
var b = new Buffer(lp, 'utf8');
140140

lib/decode.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ module.exports = exports = function (buf) {
1717
assert.equal(info.version, 2);
1818

1919
var type = buf.readUInt16BE(8);
20-
assert(type === 0 || type === 1);
20+
assert(type === 0 || type === 1, 'Type is valid');
2121
info.target.type = values.type[type];
2222

2323
var volNameLength = buf.readUInt8(10);
24-
assert(volNameLength <= 27);
24+
assert(volNameLength <= 27, 'Volume name is not longer than 27 chars');
2525
info.volume.name = buf.toString('utf8', 11, 11 + volNameLength);
2626

2727
var volCreateDate = buf.readUInt32BE(38);
2828
info.volume.created = appleDate(volCreateDate);
2929

3030
var volSig = buf.toString('ascii', 42, 44);
31-
assert(volSig === 'BD' || volSig === 'H+' || volSig === 'HX');
31+
assert(volSig === 'BD' || volSig === 'H+' || volSig === 'HX', 'Volume signature is valid');
3232
info.volume.signature = volSig;
3333

3434
var volType = buf.readUInt16BE(44);
35-
assert(volType >= 0 && volType <= 5);
35+
assert(volType >= 0 && volType <= 5, 'Volume type is valid');
3636
info.volume.type = values.volumeType[volType];
3737

3838
var dirId = buf.readUInt32BE(46);
3939
info.parent.id = dirId;
4040

4141
var fileNameLength = buf.readUInt8(50);
42-
assert(fileNameLength <= 63);
42+
assert(fileNameLength <= 63, 'File name is not longer than 63 chars');
4343
info.target.filename = buf.toString('utf8', 51, 51 + fileNameLength);
4444

4545
var fileId = buf.readUInt32BE(114);
@@ -63,11 +63,11 @@ module.exports = exports = function (buf) {
6363
// I have only encountered 00 00
6464

6565
var reserved = buf.slice(140, 150);
66-
assert(reserved[0] === 0 && reserved[1] === 0);
67-
assert(reserved[2] === 0 && reserved[3] === 0);
68-
assert(reserved[4] === 0 && reserved[5] === 0);
69-
assert(reserved[6] === 0 && reserved[7] === 0);
70-
assert(reserved[8] === 0 && reserved[9] === 0);
66+
assert(reserved[0] === 0 && reserved[1] === 0, 'Reserved is zero-filled');
67+
assert(reserved[2] === 0 && reserved[3] === 0, 'Reserved is zero-filled');
68+
assert(reserved[4] === 0 && reserved[5] === 0, 'Reserved is zero-filled');
69+
assert(reserved[6] === 0 && reserved[7] === 0, 'Reserved is zero-filled');
70+
assert(reserved[8] === 0 && reserved[9] === 0, 'Reserved is zero-filled');
7171

7272
var pos = 150;
7373

lib/encode.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ module.exports = exports = function (info) {
3434
buf.writeUInt16BE(info.version, 6)
3535

3636
var type = values.type.indexOf(info.target.type);
37-
assert(type === 0 || type === 1);
37+
assert(type === 0 || type === 1, 'Type is valid');
3838
buf.writeUInt16BE(type, 8);
3939

4040
var volNameLength = info.volume.name.length;
41-
assert(volNameLength <= 27);
41+
assert(volNameLength <= 27, 'Volume name is not longer than 27 chars');
4242
buf.writeUInt8(volNameLength, 10);
4343
buf.fill(0, 11, 11 + 27)
4444
buf.write(info.volume.name, 11, 'utf8');
@@ -47,17 +47,17 @@ module.exports = exports = function (info) {
4747
buf.writeUInt32BE(volCreateDate, 38);
4848

4949
var volSig = info.volume.signature;
50-
assert(volSig === 'BD' || volSig === 'H+' || volSig === 'HX');
50+
assert(volSig === 'BD' || volSig === 'H+' || volSig === 'HX', 'Volume signature is valid');
5151
buf.write(volSig, 42, 'ascii');
5252

5353
var volType = values.volumeType.indexOf(info.volume.type);
54-
assert(volType >= 0 && volType <= 5);
54+
assert(volType >= 0 && volType <= 5, 'Volume type is valid');
5555
buf.writeUInt16BE(volType, 44);
5656

5757
buf.writeUInt32BE(info.parent.id, 46);
5858

5959
var fileNameLength = info.target.filename.length;
60-
assert(fileNameLength <= 63);
60+
assert(fileNameLength <= 63, 'File name is not longer than 63 chars');
6161
buf.writeUInt8(fileNameLength, 50);
6262
buf.fill(0, 51, 51 + 63);
6363
buf.write(info.target.filename, 51, 'utf8');
@@ -95,7 +95,7 @@ module.exports = exports = function (info) {
9595
for (var i = 0; i < info.extra.length; i++) {
9696

9797
var e = info.extra[i];
98-
assert(e.type >= 0);
98+
assert(e.type >= 0, 'Type is valid');
9999

100100
buf.writeInt16BE(e.type, pos);
101101
buf.writeUInt16BE(e.length, pos + 2);

0 commit comments

Comments
 (0)