Attention is currently required from: Ian Lance Taylor.
Dmitri Shuralyov would like Ian Lance Taylor to review this change.
internal/short: include invalid input in error
If the input is invalid, it generally helps to see it (including any
invisible characters as printed by %q) in the error message. Do that.
Change-Id: Ibe179a7c03c29b1caa0532aff08cee1b11fbb051
---
M internal/short/short.go
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/internal/short/short.go b/internal/short/short.go
index 8cbbb59..7c4c798 100644
--- a/internal/short/short.go
+++ b/internal/short/short.go
@@ -192,10 +192,10 @@
// putLink validates the provided link and puts it into the datastore.
func (h server) putLink(ctx context.Context, link *Link) error {
if !validKey.MatchString(link.Key) {
- return errors.New("invalid key; must match " + validKey.String())
+ return fmt.Errorf("invalid key %q; must match %s", link.Key, validKey.String())
}
if _, err := url.Parse(link.Target); err != nil {
- return fmt.Errorf("bad target: %v", err)
+ return fmt.Errorf("bad target %q: %v", link.Target, err)
}
k := datastore.NameKey(kind, link.Key, nil)
_, err := h.datastore.Put(ctx, k, link)
To view, visit change 406354. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Dmitri Shuralyov, Ian Lance Taylor.
Patch set 1:Code-Review +2
Attention is currently required from: Dmitri Shuralyov, Ian Lance Taylor.
Patch set 1:Auto-Submit +1Code-Review +1
Gopher Robot submitted this change.
internal/short: include invalid input in error
If the input is invalid, it generally helps to see it (including any
invisible characters as printed by %q) in the error message. Do that.
Change-Id: Ibe179a7c03c29b1caa0532aff08cee1b11fbb051
Reviewed-on: https://go-review.googlesource.com/c/website/+/406354
TryBot-Result: Gopher Robot <go...@golang.org>
Run-TryBot: Dmitri Shuralyov <dmit...@golang.org>
Auto-Submit: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Ian Lance Taylor <ia...@google.com>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
---
M internal/short/short.go
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/internal/short/short.go b/internal/short/short.go
index 8cbbb59..7c4c798 100644
--- a/internal/short/short.go
+++ b/internal/short/short.go
@@ -192,10 +192,10 @@
// putLink validates the provided link and puts it into the datastore.
func (h server) putLink(ctx context.Context, link *Link) error {
if !validKey.MatchString(link.Key) {
- return errors.New("invalid key; must match " + validKey.String())
+ return fmt.Errorf("invalid key %q; must match %s", link.Key, validKey.String())
}
if _, err := url.Parse(link.Target); err != nil {
- return fmt.Errorf("bad target: %v", err)
+ return fmt.Errorf("bad target %q: %v", link.Target, err)
}
k := datastore.NameKey(kind, link.Key, nil)
_, err := h.datastore.Put(ctx, k, link)
To view, visit change 406354. To unsubscribe, or for help writing mail filters, visit settings.