Fix the error reporting

This commit is contained in:
Miek Gieben 2012-05-20 15:48:20 +02:00
parent 251f3973f0
commit 848e805331

View File

@ -1,6 +1,7 @@
package dns package dns
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -32,7 +33,7 @@ func generate(l lex, c chan lex, t chan Token, o string) string {
} }
sx := strings.SplitN(l.token, "-", 2) sx := strings.SplitN(l.token, "-", 2)
if len(sx) != 2 { if len(sx) != 2 {
return "bad start/stop in $GENERATE range" return "bad start-stop in $GENERATE range"
} }
start, err := strconv.Atoi(sx[0]) start, err := strconv.Atoi(sx[0])
if err != nil { if err != nil {
@ -40,7 +41,7 @@ func generate(l lex, c chan lex, t chan Token, o string) string {
} }
end, err := strconv.Atoi(sx[1]) end, err := strconv.Atoi(sx[1])
if err != nil { if err != nil {
return "bad end in $GENERATE range" return "bad stop in $GENERATE range"
} }
if end < 0 || start < 0 || end <= start { if end < 0 || start < 0 || end <= start {
return "bad range in $GENERATE range" return "bad range in $GENERATE range"
@ -56,13 +57,14 @@ BuildRR:
goto BuildRR goto BuildRR
} }
for i := start; i <= end; i += step { for i := start; i <= end; i += step {
escape := false var (
dom := "" escape bool
// Defaults dom string
mod := "%d" mod string
offset := 0 offset int
var err error err error
// Build the domain name. )
for j := 0; j < len(s); j++ { // No 'range' because we need to jump around for j := 0; j < len(s); j++ { // No 'range' because we need to jump around
switch s[j] { switch s[j] {
case '\\': case '\\':
@ -128,11 +130,11 @@ BuildRR:
func modToPrintf(s string) (string, int, error) { func modToPrintf(s string) (string, int, error) {
xs := strings.SplitN(s, ",", 3) xs := strings.SplitN(s, ",", 3)
if len(xs) != 3 { if len(xs) != 3 {
return "", 0, nil // make error return "", 0, errors.New("fubar")
} }
// xs[0] is offset, xs[1] is width, xs[2] is base // xs[0] is offset, xs[1] is width, xs[2] is base
if xs[2] != "o" && xs[2] != "d" && xs[2] != "x" && xs[2] != "X" { if xs[2] != "o" && xs[2] != "d" && xs[2] != "x" && xs[2] != "X" {
return "", 0, nil // make error return "", 0, errors.New("fubar")
} }
offset, err := strconv.Atoi(xs[0]) offset, err := strconv.Atoi(xs[0])
if err != nil { if err != nil {
@ -145,7 +147,7 @@ func modToPrintf(s string) (string, int, error) {
printf := "%" printf := "%"
switch { switch {
case width < 0: case width < 0:
return "", offset, nil // make error return "", offset, errors.New("fubar")
case width == 0: case width == 0:
printf += xs[1] printf += xs[1]
default: default: