present: improve error for bad author block

I forgot to put in a section heading and every line
containing a colon in the text got parsed as a URL,
failing and printing errors. It took a while to find
where they were coming from.

For golang/go#33955.

Change-Id: Ibbc41a8446c292f6ab363829cf31fe594152e42d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222844
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/present/parse.go b/present/parse.go
index 35de0dd..8384f26 100644
--- a/present/parse.go
+++ b/present/parse.go
@@ -300,7 +300,7 @@
 	}
 
 	// Authors
-	if doc.Authors, err = parseAuthors(lines); err != nil {
+	if doc.Authors, err = parseAuthors(name, lines); err != nil {
 		return nil, err
 	}
 	// Sections
@@ -483,7 +483,7 @@
 	return nil
 }
 
-func parseAuthors(lines *Lines) (authors []Author, err error) {
+func parseAuthors(name string, lines *Lines) (authors []Author, err error) {
 	// This grammar demarcates authors with blanks.
 
 	// Skip blank lines.
@@ -527,11 +527,11 @@
 		var el Elem
 		switch {
 		case strings.HasPrefix(text, "@"):
-			el = parseURL("http://twitter.com/" + text[1:])
+			el = parseAuthorURL(name, "http://twitter.com/"+text[1:])
 		case strings.Contains(text, ":"):
-			el = parseURL(text)
+			el = parseAuthorURL(name, text)
 		case strings.Contains(text, "@"):
-			el = parseURL("mailto:" + text)
+			el = parseAuthorURL(name, "mailto:"+text)
 		}
 		if l, ok := el.(Link); ok {
 			l.Label = text
@@ -548,10 +548,10 @@
 	return authors, nil
 }
 
-func parseURL(text string) Elem {
+func parseAuthorURL(name, text string) Elem {
 	u, err := url.Parse(text)
 	if err != nil {
-		log.Printf("Parse(%q): %v", text, err)
+		log.Printf("parsing %s author block: invalid URL %q: %v", name, text, err)
 		return nil
 	}
 	return Link{URL: u}