errors now []byte

master
Jordan Orelli 11 years ago
parent e4314bce1b
commit 1841de74e7

@ -110,7 +110,7 @@ func main() {
response := <-responses
if response.ok() {
switch r := response.val().(type) {
case Error:
case ErrorVal:
if options.verbose {
fmt.Fprintf(os.Stderr, "%q -> %q\n", request, response.val())
} else {

@ -106,8 +106,7 @@ func readValue(r io.Reader) (value, error) {
case start_string:
return StringVal(line), nil
case start_error:
line = line[:len(line)-2]
return Error(line[1:]), nil
return ErrorVal(line), nil
case start_integer:
line = line[:len(line)-2]
return Integer(line[1:]), nil
@ -141,13 +140,23 @@ func String(s string) value {
// ------------------------------------------------------------------------------
type Error string
type ErrorVal []byte
func (e Error) Write(w io.Writer) (int, error) {
w.Write([]byte{'-'})
w.Write([]byte(e))
w.Write([]byte{'\r', '\n'})
return 0, nil
func (e ErrorVal) Write(w io.Writer) (int, error) {
// w.Write([]byte{'-'})
// w.Write([]byte(e))
// w.Write([]byte{'\r', '\n'})
// return 0, nil
return w.Write(e)
}
func Error(s string) value {
b := make(ErrorVal, len(s)+3)
b[0] = '-'
copy(b[1:], []byte(s))
b[len(b)-2] = '\r'
b[len(b)-1] = '\n'
return b
}
// ------------------------------------------------------------------------------

Loading…
Cancel
Save