Turn new validation errors in warnings.
This commit is contained in:
parent
50d2637b04
commit
9bc08236fb
1 changed files with 18 additions and 11 deletions
|
|
@ -20,6 +20,13 @@ proc newValidationError(msg: string, warnInstalled: bool): ref ValidationError =
|
||||||
result = newException(ValidationError, msg)
|
result = newException(ValidationError, msg)
|
||||||
result.warnInstalled = warnInstalled
|
result.warnInstalled = warnInstalled
|
||||||
|
|
||||||
|
proc raiseNewValidationError(msg: string, warnInstalled: bool) =
|
||||||
|
if warnInstalled:
|
||||||
|
# TODO: We warn everywhere for now. Raise the error in the next version.
|
||||||
|
echo("WARNING: ", msg, ". Will be an error in next version!")
|
||||||
|
else:
|
||||||
|
raiseNewValidationError(msg, warnInstalled)
|
||||||
|
|
||||||
proc validatePackageName*(name: string) =
|
proc validatePackageName*(name: string) =
|
||||||
## Raises an error if specified package name contains invalid characters.
|
## Raises an error if specified package name contains invalid characters.
|
||||||
##
|
##
|
||||||
|
|
@ -28,7 +35,7 @@ proc validatePackageName*(name: string) =
|
||||||
if name.len == 0: return
|
if name.len == 0: return
|
||||||
|
|
||||||
if name[0] in {'0'..'9'}:
|
if name[0] in {'0'..'9'}:
|
||||||
raise newValidationError(name &
|
raiseNewValidationError(name &
|
||||||
"\"$1\" is an invalid package name: cannot begin with $2" %
|
"\"$1\" is an invalid package name: cannot begin with $2" %
|
||||||
[name, $name[0]], true)
|
[name, $name[0]], true)
|
||||||
|
|
||||||
|
|
@ -37,11 +44,11 @@ proc validatePackageName*(name: string) =
|
||||||
case c
|
case c
|
||||||
of '_':
|
of '_':
|
||||||
if prevWasUnderscore:
|
if prevWasUnderscore:
|
||||||
raise newValidationError(
|
raiseNewValidationError(
|
||||||
"$1 is an invalid package name: cannot contain \"__\"" % name, true)
|
"$1 is an invalid package name: cannot contain \"__\"" % name, true)
|
||||||
prevWasUnderscore = true
|
prevWasUnderscore = true
|
||||||
of AllChars - IdentChars:
|
of AllChars - IdentChars:
|
||||||
raise newValidationError(
|
raiseNewValidationError(
|
||||||
"$1 is an invalid package name: cannot contain '$2'" % [name, $c],
|
"$1 is an invalid package name: cannot contain '$2'" % [name, $c],
|
||||||
true)
|
true)
|
||||||
else:
|
else:
|
||||||
|
|
@ -50,35 +57,35 @@ proc validatePackageName*(name: string) =
|
||||||
proc validateVersion*(ver: string) =
|
proc validateVersion*(ver: string) =
|
||||||
for c in ver:
|
for c in ver:
|
||||||
if c notin ({'.'} + Digits):
|
if c notin ({'.'} + Digits):
|
||||||
raise newValidationError(
|
raiseNewValidationError(
|
||||||
"Version may only consist of numbers and the '.' character " &
|
"Version may only consist of numbers and the '.' character " &
|
||||||
"but found '" & c & "'.", false)
|
"but found '" & c & "'.", false)
|
||||||
|
|
||||||
proc validatePackageInfo(pkgInfo: PackageInfo, path: string) =
|
proc validatePackageInfo(pkgInfo: PackageInfo, path: string) =
|
||||||
if pkgInfo.name == "":
|
if pkgInfo.name == "":
|
||||||
raise newValidationError("Incorrect .nimble file: " & path &
|
raiseNewValidationError("Incorrect .nimble file: " & path &
|
||||||
" does not contain a name field.", false)
|
" does not contain a name field.", false)
|
||||||
|
|
||||||
if pkgInfo.name.normalize != path.splitFile.name.normalize:
|
if pkgInfo.name.normalize != path.splitFile.name.normalize:
|
||||||
raise newValidationError(
|
raiseNewValidationError(
|
||||||
"The .nimble file name must match name specified inside " & path, true)
|
"The .nimble file name must match name specified inside " & path, true)
|
||||||
|
|
||||||
if pkgInfo.version == "":
|
if pkgInfo.version == "":
|
||||||
raise newValidationError("Incorrect .nimble file: " & path &
|
raiseNewValidationError("Incorrect .nimble file: " & path &
|
||||||
" does not contain a version field.", false)
|
" does not contain a version field.", false)
|
||||||
|
|
||||||
if not pkgInfo.isMinimal:
|
if not pkgInfo.isMinimal:
|
||||||
if pkgInfo.author == "":
|
if pkgInfo.author == "":
|
||||||
raise newValidationError("Incorrect .nimble file: " & path &
|
raiseNewValidationError("Incorrect .nimble file: " & path &
|
||||||
" does not contain an author field.", false)
|
" does not contain an author field.", false)
|
||||||
if pkgInfo.description == "":
|
if pkgInfo.description == "":
|
||||||
raise newValidationError("Incorrect .nimble file: " & path &
|
raiseNewValidationError("Incorrect .nimble file: " & path &
|
||||||
" does not contain a description field.", false)
|
" does not contain a description field.", false)
|
||||||
if pkgInfo.license == "":
|
if pkgInfo.license == "":
|
||||||
raise newValidationError("Incorrect .nimble file: " & path &
|
raiseNewValidationError("Incorrect .nimble file: " & path &
|
||||||
" does not contain a license field.", false)
|
" does not contain a license field.", false)
|
||||||
if pkgInfo.backend notin ["c", "cc", "objc", "cpp", "js"]:
|
if pkgInfo.backend notin ["c", "cc", "objc", "cpp", "js"]:
|
||||||
raise newValidationError("'" & pkgInfo.backend &
|
raiseNewValidationError("'" & pkgInfo.backend &
|
||||||
"' is an invalid backend.", false)
|
"' is an invalid backend.", false)
|
||||||
|
|
||||||
validateVersion(pkgInfo.version)
|
validateVersion(pkgInfo.version)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue