From 720659ff3424459a4e9c7d9b2dd1a0318a394198 Mon Sep 17 00:00:00 2001 From: Ayan George Date: Sun, 26 Nov 2017 21:07:11 -0500 Subject: [PATCH] Move error handling to the top of Parse() --- adstxt.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/adstxt.go b/adstxt.go index 478cca4..5525ca5 100644 --- a/adstxt.go +++ b/adstxt.go @@ -76,17 +76,16 @@ func (a *AdsTxt) parseVariable(line string) error { // Parse parses the supplied adx.txt data and returns a packed AdsTxt // structure. func Parse(srcurl, txt string) (AdsTxt, error) { + if txt == "" { + return rc, fmt.Errorf("given an empty string; nothing to parse") + } + rc := AdsTxt{ Source: srcurl, Variable: make(map[string][]string), } - if txt == "" { - return rc, fmt.Errorf("given an empty string; nothing to parse") - } - // create a scanner that reads line by line. - for scanner := bufio.NewScanner(strings.NewReader(txt)); scanner.Scan(); { line := strings.TrimSpace(scanner.Text())