code review 36520044: gosshnew/ssh: add more diagnostics to Marshal/Unmarshal... (issue 36520044)

19 views
Skip to first unread message

han...@google.com

unread,
Dec 18, 2013, 5:56:17 AM12/18/13
to a...@golang.org, da...@cheney.net, jps...@google.com, a...@golang.org, da...@cheney.net, golan...@googlegroups.com, jps...@google.com, re...@codereview-hr.appspotmail.com
Reviewers: agl1, dfc, jpsugar,

Message:
Hello agl1, da...@cheney.net, jps...@google.com (cc: a...@golang.org,
da...@cheney.net, golan...@googlegroups.com, han...@google.com,
jps...@google.com),

I'd like you to review this change to
https://hanwen%40goog...@code.google.com/p/gosshnew/


Description:
gosshnew/ssh: add more diagnostics to Marshal/Unmarshal failures

Please review this at https://codereview.appspot.com/36520044/

Affected files (+7, -7 lines):
M ssh/messages.go


Index: ssh/messages.go
===================================================================
--- a/ssh/messages.go
+++ b/ssh/messages.go
@@ -299,7 +299,7 @@
data = data[1:]
case reflect.Array:
if t.Elem().Kind() != reflect.Uint8 {
- panic("array of non-uint8")
+ return fmt.Errorf("array of unsupported type in field %d: %T", i,
field.Interface())
}
if len(data) < t.Len() {
return ParseError{expectedType}
@@ -340,7 +340,7 @@
}
field.Set(reflect.ValueOf(nl))
default:
- panic("slice of unknown type")
+ return fmt.Errorf("slice to unknown type in field %d: %T", i,
field.Interface())
}
case reflect.Ptr:
if t == bigIntType {
@@ -350,10 +350,10 @@
}
field.Set(reflect.ValueOf(n))
} else {
- panic("pointer to unknown type")
+ return fmt.Errorf("pointer to unknown in field %d: %T", i,
field.Interface())
}
default:
- panic("unknown type")
+ return fmt.Errorf("unknown type in field %d: %T", field.Interface(), i)
}
}

@@ -392,7 +392,7 @@
out = append(out, v)
case reflect.Array:
if t.Elem().Kind() != reflect.Uint8 {
- panic("array of non-uint8")
+ panic(fmt.Sprintf("array of non-uint8 in field %d: %T", i,
field.Interface()))
}
for j, l := 0, t.Len(); j < l; j++ {
out = append(out, uint8(field.Index(j).Uint()))
@@ -425,7 +425,7 @@
binary.BigEndian.PutUint32(out[offset:], uint32(len(out)-offset-4))
}
default:
- panic("slice of unknown type")
+ panic(fmt.Sprintf("slice of unknown type in field %d: %T", i,
field.Interface()))
}
case reflect.Ptr:
if t == bigIntType {
@@ -443,7 +443,7 @@
out = out[:oldLength+needed]
marshalInt(out[oldLength:], n)
} else {
- panic("pointer to unknown type")
+ panic(fmt.Sprintf("pointer to unknown type in field %d: %T", i,
field.Interface()))
}
}
}


jps...@google.com

unread,
Dec 18, 2013, 3:16:31 PM12/18/13
to han...@google.com, a...@golang.org, da...@cheney.net, a...@golang.org, da...@cheney.net, golan...@googlegroups.com, han...@google.com, re...@codereview-hr.appspotmail.com

a...@golang.org

unread,
Dec 18, 2013, 3:19:43 PM12/18/13
to han...@google.com, da...@cheney.net, jps...@google.com, da...@cheney.net, golan...@googlegroups.com, han...@google.com, jps...@google.com, re...@codereview-hr.appspotmail.com

han...@google.com

unread,
Dec 19, 2013, 4:38:14 AM12/19/13
to han...@google.com, a...@golang.org, da...@cheney.net, jps...@google.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
*** Submitted as
https://code.google.com/p/gosshnew/source/detail?r=b78c3da92890 ***

gosshnew/ssh: add more diagnostics to Marshal/Unmarshal failures

R=agl, dave, jpsugar
CC=agl, dave, golang-dev, hanwen, jpsugar
https://codereview.appspot.com/36520044


https://codereview.appspot.com/36520044/
Reply all
Reply to author
Forward
0 new messages