Skip to content

Commit

Permalink
convert some manual throws to asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Nov 12, 2010
1 parent 2e34850 commit 5e2c8fe
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,17 @@ ddoc.validate_doc_update = function (newDoc, oldDoc, user) {
}
function isAdmin () { return user.roles.indexOf("_admin") >= 0 }

if (!validUser()) {
throw {forbidden:"user: " + user.name + " not authorized to modify "
+ newDoc.name }
}
assert(validUser(), "user: " + user.name + " not authorized to modify "
+ newDoc.name )
if (newDoc._deleted) return

if (oldDoc && oldDoc.maintainers && !newDoc.maintainers) {
throw {forbidden: "Please upgrade your package manager program"}
}
assert(newDoc.maintainers, "Please upgrade your package manager program")
var n = valid.name(newDoc.name)
if (!valid.name(n) || n !== newDoc.name || !n) {
var msg = "Invalid name: "
+ JSON.stringify(newDoc.name)
+ " may not start with '.' or contain '/' or '@' or whitespace"
throw {forbidden:msg}
}

assert(valid.name(n) && n === newDoc.name && n
, "Invalid name: "
+ JSON.stringify(newDoc.name)
+ " may not start with '.' or contain '/' or '@' or whitespace")

// make sure all the dist-tags and versions are valid semver
assert(newDoc["dist-tags"], "must have dist-tags")
assert(newDoc.versions, "must have versions")
Expand All @@ -321,7 +315,6 @@ ddoc.validate_doc_update = function (newDoc, oldDoc, user) {
"dist-tag "+i+" refers to non-existent version: "+newDoc["dist-tags"][i])
}
for (var i in newDoc.versions) {
assert(semver.valid(i),
"version "+i+" is not a valid version")
assert(semver.valid(i), "version "+i+" is not a valid version")
}
}

0 comments on commit 5e2c8fe

Please sign in to comment.