Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw Error instances instead of strings #12

Merged
merged 2 commits into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: "node_js"
node_js:
- 0.4
- 0.5
- 0.6
- 0.8
- 0.10
- 0.11
10 changes: 5 additions & 5 deletions jsonpointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var untilde = function(str) {
case "~1":
return "/";
}
throw("Invalid tilde escape: " + m);
throw new Error("Invalid tilde escape: " + m);
});
}

Expand Down Expand Up @@ -38,21 +38,21 @@ var traverse = function(obj, pointer, value) {

var validate_input = function(obj, pointer) {
if(typeof obj !== "object") {
throw("Invalid input object.");
throw new Error("Invalid input object.");
}

if(pointer === "") {
return [];
}

if(!pointer) {
throw("Invalid JSON pointer.");
throw new Error("Invalid JSON pointer.");
}

pointer = pointer.split("/");
var first = pointer.shift();
if (first !== "") {
throw("Invalid JSON pointer.");
throw new Error("Invalid JSON pointer.");
}

return pointer;
Expand All @@ -69,7 +69,7 @@ var get = function(obj, pointer) {
var set = function(obj, pointer, value) {
pointer = validate_input(obj, pointer);
if (pointer.length === 0) {
throw("Invalid JSON pointer for set.")
throw new Error("Invalid JSON pointer for set.")
}
return traverse(obj, pointer, value);
}
Expand Down