Skip to content

Commit d92bfec

Browse files
committed
Merge pull request neo4j#54 from pontusmelke/1.0-unified-errors
1.0 unified errors
2 parents 7134ab2 + 593645a commit d92bfec

File tree

11 files changed

+31
-26
lines changed

11 files changed

+31
-26
lines changed

src/v1/internal/error.js renamed to src/v1/error.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function newError(message, code="N/A") {
2626
return new Neo4jError(message, code);
2727
}
2828

29-
// TODO: This should be moved into public API
3029
class Neo4jError extends Error {
3130
constructor( message, code="N/A" ) {
3231
super( message );

src/v1/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import {int, isInt} from './integer';
2121
import {driver} from './driver';
2222
import {Node, Relationship, UnboundRelationship, PathSegment, Path} from './graph-types'
23-
23+
import {Neo4jError} from './error';
2424
export default {
2525
driver,
2626
int,
2727
isInt,
28+
Neo4jError,
2829
auth: {
2930
basic: (username, password) => {
3031
return {scheme: "basic", principal: username, credentials: password};

src/v1/integer.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// https://github.com/dcodeIO/Long.js
2222
// License Apache 2
2323

24+
import {newError} from "./error";
25+
2426
/**
2527
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
2628
* See the from* functions below for more convenient ways of constructing Integers.
@@ -407,7 +409,7 @@ class Integer {
407409
if (!Integer.isInteger(divisor))
408410
divisor = Integer.fromValue(divisor);
409411
if (divisor.isZero())
410-
throw(new Error('division by zero'));
412+
throw newError('division by zero');
411413
if (this.isZero())
412414
return Integer.ZERO;
413415
var approx, rem, res;
@@ -666,16 +668,16 @@ Integer.fromBits = function(lowBits, highBits) {
666668
*/
667669
Integer.fromString = function(str, radix) {
668670
if (str.length === 0)
669-
throw Error('number format error: empty string');
671+
throw newError('number format error: empty string');
670672
if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
671673
return Integer.ZERO;
672674
radix = radix || 10;
673675
if (radix < 2 || 36 < radix)
674-
throw Error('radix out of range: ' + radix);
676+
throw newError('radix out of range: ' + radix);
675677

676678
var p;
677679
if ((p = str.indexOf('-')) > 0)
678-
throw Error('number format error: interior "-" character: ' + str);
680+
throw newError('number format error: interior "-" character: ' + str);
679681
else if (p === 0)
680682
return Integer.fromString(str.substring(1), radix).negate();
681683

src/v1/internal/buf.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*(via Buffer API).
2323
*/
2424

25+
import {newError} from './../error';
2526
let _node = require("buffer");
2627
/**
2728
* Common base with default implementation for most buffer methods.
@@ -465,7 +466,7 @@ class CombinedBuffer extends BaseBuffer {
465466
let length = 0;
466467
for (let i = 0; i < buffers.length; i++) {
467468
length += buffers[i].length;
468-
};
469+
}
469470
super( length );
470471
this._buffers = buffers;
471472
}
@@ -480,7 +481,7 @@ class CombinedBuffer extends BaseBuffer {
480481
} else {
481482
return buffer.getUInt8(position);
482483
}
483-
};
484+
}
484485
}
485486

486487
getInt8 ( position ) {
@@ -547,10 +548,10 @@ class NodeBuffer extends BaseBuffer {
547548
this._buffer,
548549
position,
549550
val.position,
550-
val.position + bytesToCopy )
551+
val.position + bytesToCopy );
551552
val.position += bytesToCopy;
552553
} else {
553-
throw new Error("Copying not yet implemented.");
554+
throw newError("Copying not yet implemented.");
554555
}
555556
};
556557

src/v1/internal/ch-node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import fs from 'fs';
2323
import path from 'path';
2424
import {EOL} from 'os';
2525
import {NodeBuffer} from './buf';
26-
import {newError} from './error';
26+
import {newError} from './../error';
2727

2828
let _CONNECTION_IDGEN = 0;
2929

@@ -228,7 +228,7 @@ class NodeChannel {
228228
// console.log( "[Conn#"+this.id+"] SEND: ", buffer.toString() );
229229
this._conn.write( buffer._buffer );
230230
} else {
231-
throw new Error( "Don't know how to write: " + buffer );
231+
throw newError( "Don't know how to write: " + buffer );
232232
}
233233
}
234234

src/v1/internal/ch-websocket.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import {debug} from "./log";
2121
import {HeapBuffer} from "./buf";
22-
import {newError} from './error';
22+
import {newError} from './../error';
2323

2424
/**
2525
* Create a new WebSocketChannel to be used in web browsers.
@@ -111,7 +111,7 @@ class WebSocketChannel {
111111
} else if( buffer instanceof HeapBuffer ) {
112112
this._ws.send( buffer._buffer );
113113
} else {
114-
throw new Error( "Don't know how to send buffer: " + buffer );
114+
throw newError( "Don't know how to send buffer: " + buffer );
115115
}
116116
}
117117

src/v1/internal/connector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import packstream from "./packstream";
2525
import {alloc, CombinedBuffer} from "./buf";
2626
import GraphType from '../graph-types';
2727
import {int, isInt} from '../integer';
28-
import {newError} from './error';
28+
import {newError} from './../error';
2929

3030
let Channel;
3131
if( WebSocketChannel.available ) {
@@ -35,7 +35,7 @@ else if( NodeChannel.available ) {
3535
Channel = NodeChannel.channel;
3636
}
3737
else {
38-
throw new Error("Fatal: No compatible transport available. Need to run on a platform with the WebSocket API.");
38+
throw newError("Fatal: No compatible transport available. Need to run on a platform with the WebSocket API.");
3939
}
4040

4141

src/v1/internal/packstream.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {debug} from "./log";
2121
import {alloc} from "./buf";
2222
import utf8 from "./utf8";
2323
import {Integer, int} from "../integer";
24+
import {newError} from './../error';
2425

2526
let MAX_CHUNK_SIZE = 16383,
2627
TINY_STRING = 0x80,
@@ -108,7 +109,7 @@ class Packer {
108109
this.pack(x[key]);
109110
}
110111
} else {
111-
throw new Error("Cannot pack this value: " + x);
112+
throw newError("Cannot pack this value: " + x);
112113
}
113114
}
114115

@@ -174,7 +175,7 @@ class Packer {
174175
this._ch.writeUInt8(size%256);
175176
this._ch.writeBytes(bytes);
176177
} else {
177-
throw new ProtocolError("UTF-8 strings of size " + size + " are not supported");
178+
throw newError("UTF-8 strings of size " + size + " are not supported");
178179
}
179180
}
180181

@@ -195,7 +196,7 @@ class Packer {
195196
this._ch.writeUInt8((size/256>>0)%256);
196197
this._ch.writeUInt8(size%256);
197198
} else {
198-
throw new ProtocolError("Lists of size " + size + " are not supported");
199+
throw newError("Lists of size " + size + " are not supported");
199200
}
200201
}
201202

@@ -216,7 +217,7 @@ class Packer {
216217
this._ch.writeUInt8((size/256>>0)%256);
217218
this._ch.writeUInt8(size%256);
218219
} else {
219-
throw new ProtocolError("Maps of size " + size + " are not supported");
220+
throw newError("Maps of size " + size + " are not supported");
220221
}
221222
}
222223

@@ -233,7 +234,7 @@ class Packer {
233234
this._ch.writeUInt8(size/256>>0);
234235
this._ch.writeUInt8(size%256);
235236
} else {
236-
throw new ProtocolError("Structures of size " + size + " are not supported");
237+
throw newError("Structures of size " + size + " are not supported");
237238
}
238239
}
239240
}
@@ -340,13 +341,13 @@ class Unpacker {
340341
} else if (markerHigh == 0xB0) {
341342
return this.unpackStruct(markerLow, buffer);
342343
} else {
343-
throw new ProtocolError("Unknown packed value with marker " + marker.toString(16));
344+
throw newError("Unknown packed value with marker " + marker.toString(16));
344345
}
345346
}
346347
}
347348

348349
export default {
349350
Packer,
350351
Unpacker,
351-
Structure,
352+
Structure
352353
};

src/v1/internal/utf8.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import buf from "./buf";
2424
import {StringDecoder} from 'string_decoder';
25+
import {newError} from './../error';
2526
let platformObj = {};
2627

2728

@@ -52,7 +53,7 @@ try {
5253
return out;
5354
}
5455
else {
55-
throw new Error( "Don't know how to decode strings from `" + buffer + "`.");
56+
throw newError( "Don't know how to decode strings from `" + buffer + "`.");
5657
}
5758
}
5859
}

src/v1/record.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
import {newError} from "./internal/error";
20+
import {newError} from "./error";
2121

2222
function generateFieldLookup( keys ) {
2323
let lookup = {};

src/v1/session.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Session {
7474
*/
7575
beginTransaction() {
7676
if (this._hasTx) {
77-
throw new Error("Cannot have multiple transactions open for the session. Use multiple sessions or close the transaction before opening a new one.")
77+
throw new newError("Cannot have multiple transactions open for the session. Use multiple sessions or close the transaction before opening a new one.")
7878
}
7979

8080
this._hasTx = true;

0 commit comments

Comments
 (0)