go.talks/pkg/present: remove remaining log.Fatal calls
R=bsiegert
CC=golang-dev
https://golang.org/cl/7311092
diff --git a/pkg/present/code.go b/pkg/present/code.go
index 6ab60ae..624552a 100644
--- a/pkg/present/code.go
+++ b/pkg/present/code.go
@@ -7,7 +7,6 @@
import (
"fmt"
"html/template"
- "log"
"path/filepath"
"regexp"
"strconv"
@@ -152,18 +151,17 @@
}
// parseArg returns the integer or string value of the argument and tells which it is.
-func parseArg(arg interface{}, file string, max int) (ival int, sval string, isInt bool) {
+func parseArg(arg interface{}, max int) (ival int, sval string, isInt bool, err error) {
switch n := arg.(type) {
case int:
if n <= 0 || n > max {
- log.Fatalf("%q:%d is out of range", file, n)
+ return 0, "", false, fmt.Errorf("%%d is out of range", n)
}
- return n, "", true
+ return n, "", true, nil
case string:
- return 0, n, false
+ return 0, n, false, nil
}
- log.Fatalf("unrecognized argument %v type %T", arg, arg)
- return
+ return 0, "", false, fmt.Errorf("unrecognized argument %v type %T", arg, arg)
}
// oneLine returns the single line generated by a two-argument code invocation.
@@ -173,7 +171,10 @@
return "", "", "", err
}
lines := strings.SplitAfter(string(contentBytes), "\n")
- lineNum, pattern, isInt := parseArg(arg, file, len(lines))
+ lineNum, pattern, isInt, err := parseArg(arg, len(lines))
+ if err != nil {
+ return "", "", "", err
+ }
var n int
if isInt {
n = lineNum - 1
@@ -197,8 +198,14 @@
if err != nil {
return "", "", "", err
}
- line1, pattern1, isInt1 := parseArg(arg1, file, len(lines))
- line2, pattern2, isInt2 := parseArg(arg2, file, len(lines))
+ line1, pattern1, isInt1, err := parseArg(arg1, len(lines))
+ if err != nil {
+ return "", "", "", err
+ }
+ line2, pattern2, isInt2, err := parseArg(arg2, len(lines))
+ if err != nil {
+ return "", "", "", err
+ }
if !isInt1 {
line1, err = match(file, 0, lines, pattern1)
}