From 7872b8d9115c983b3d7243415a00b3124169f840 Mon Sep 17 00:00:00 2001 From: Larpon Date: Wed, 30 Dec 2020 17:07:21 +0100 Subject: [PATCH] semver: add input information in error and panic output (#7712) --- vlib/semver/range.v | 6 ++++-- vlib/semver/semver.v | 6 ++++-- vlib/semver/util.v | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/vlib/semver/range.v b/vlib/semver/range.v index 60531c0a24..54c7f927fa 100644 --- a/vlib/semver/range.v +++ b/vlib/semver/range.v @@ -74,11 +74,13 @@ fn parse_range(input string) ?Range { fn parse_comparator_set(input string) ?ComparatorSet { raw_comparators := input.split(comparator_sep) if raw_comparators.len > 2 { - return error('Invalid format of comparator set') + return error('Invalid format of comparator set for input "$input"') } mut comparators := []Comparator{} for raw_comp in raw_comparators { - c := parse_comparator(raw_comp) or { return error('Invalid comparator: $raw_comp') } + c := parse_comparator(raw_comp) or { + return error('Invalid comparator "$raw_comp" in input "$input"') + } comparators << c } return ComparatorSet{comparators} diff --git a/vlib/semver/semver.v b/vlib/semver/semver.v index fe872921d5..c5ea13686d 100644 --- a/vlib/semver/semver.v +++ b/vlib/semver/semver.v @@ -26,7 +26,9 @@ pub fn from(input string) ?Version { return error('Empty input') } raw_version := parse(input) - version := raw_version.validate() or { return error('Invalid version format') } + version := raw_version.validate() or { + return error('Invalid version format for input "$input"') + } return version } @@ -69,7 +71,7 @@ pub fn (v1 Version) le(v2 Version) bool { // * Utilites. pub fn coerce(input string) ?Version { - ver := coerce_version(input) or { return error('Invalid version: $input') } + ver := coerce_version(input) or { return error('Invalid version for input "$input"') } return ver } diff --git a/vlib/semver/util.v b/vlib/semver/util.v index 5e9c02672d..142ce196da 100644 --- a/vlib/semver/util.v +++ b/vlib/semver/util.v @@ -10,7 +10,7 @@ fn is_version_valid(input string) bool { [inline] fn coerce_version(input string) ?Version { raw_ver := parse(input) - ver := raw_ver.coerce() or { return error('Invalid version: $input') } + ver := raw_ver.coerce() or { return error('Invalid version for input "$input"') } return ver }