Replaced quit() in packageinfo with an exception.
This commit is contained in:
parent
cf17779d4e
commit
7b09600b84
1 changed files with 10 additions and 8 deletions
|
|
@ -90,7 +90,8 @@ proc parseRequires(req: string): tuple[name: string, ver: PVersionRange] =
|
||||||
result.name = req.strip
|
result.name = req.strip
|
||||||
result.ver = PVersionRange(kind: verAny)
|
result.ver = PVersionRange(kind: verAny)
|
||||||
except EParseVersion:
|
except EParseVersion:
|
||||||
quit("Unable to parse dependency version range: " & getCurrentExceptionMsg())
|
raise newException(EBabel, "Unable to parse dependency version range: " &
|
||||||
|
getCurrentExceptionMsg())
|
||||||
|
|
||||||
proc multiSplit(s: string): seq[string] =
|
proc multiSplit(s: string): seq[string] =
|
||||||
## Returns ``s`` split by newline and comma characters.
|
## Returns ``s`` split by newline and comma characters.
|
||||||
|
|
@ -153,18 +154,18 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
||||||
case result.backend.normalize
|
case result.backend.normalize
|
||||||
of "javascript": result.backend = "js"
|
of "javascript": result.backend = "js"
|
||||||
else:
|
else:
|
||||||
quit("Invalid field: " & ev.key, QuitFailure)
|
raise newException(EBabel, "Invalid field: " & ev.key)
|
||||||
of "deps", "dependencies":
|
of "deps", "dependencies":
|
||||||
case ev.key.normalize
|
case ev.key.normalize
|
||||||
of "requires":
|
of "requires":
|
||||||
for v in ev.value.multiSplit:
|
for v in ev.value.multiSplit:
|
||||||
result.requires.add(parseRequires(v.strip))
|
result.requires.add(parseRequires(v.strip))
|
||||||
else:
|
else:
|
||||||
quit("Invalid field: " & ev.key, QuitFailure)
|
raise newException(EBabel, "Invalid field: " & ev.key)
|
||||||
else: quit("Invalid section: " & currentSection, QuitFailure)
|
else: raise newException(EBabel, "Invalid section: " & currentSection)
|
||||||
of cfgOption: quit("Invalid package info, should not contain --" & ev.value, QuitFailure)
|
of cfgOption: raise newException(EBabel, "Invalid package info, should not contain --" & ev.value)
|
||||||
of cfgError:
|
of cfgError:
|
||||||
echo(ev.msg)
|
raise newException(EBabel, "Error parsing .babel file: " & ev.msg)
|
||||||
close(p)
|
close(p)
|
||||||
else:
|
else:
|
||||||
raise newException(EInvalidValue, "Cannot open package info: " & path)
|
raise newException(EInvalidValue, "Cannot open package info: " & path)
|
||||||
|
|
@ -180,7 +181,7 @@ proc optionalField(obj: PJsonNode, name: string, default = ""): string =
|
||||||
if obj[name].kind == JString:
|
if obj[name].kind == JString:
|
||||||
return obj[name].str
|
return obj[name].str
|
||||||
else:
|
else:
|
||||||
quit("Corrupted packages.json file. " & name & " field is of unexpected type.")
|
raise newException(EBabel, "Corrupted packages.json file. " & name & " field is of unexpected type.")
|
||||||
else: return default
|
else: return default
|
||||||
|
|
||||||
proc requiredField(obj: PJsonNode, name: string): string =
|
proc requiredField(obj: PJsonNode, name: string): string =
|
||||||
|
|
@ -189,7 +190,8 @@ proc requiredField(obj: PJsonNode, name: string): string =
|
||||||
## Aborts execution if the field does not exist or is of invalid json type.
|
## Aborts execution if the field does not exist or is of invalid json type.
|
||||||
result = optionalField(obj, name, nil)
|
result = optionalField(obj, name, nil)
|
||||||
if result == nil:
|
if result == nil:
|
||||||
quit("Package in packages.json file does not contain a " & name & " field.")
|
raise newException(EBabel,
|
||||||
|
"Package in packages.json file does not contain a " & name & " field.")
|
||||||
|
|
||||||
proc fromJson(obj: PJSonNode): TPackage =
|
proc fromJson(obj: PJSonNode): TPackage =
|
||||||
## Constructs a TPackage object from a JSON node.
|
## Constructs a TPackage object from a JSON node.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue