~samwhited/xmpp

d99cc4f65bce945bd70af9986b534ded7bc41feb — Sam Whited 9 months ago 7ae6a69
component: fix error convention

Fix errors to use messages that follow the convention used in other
packages in this module.

Signed-off-by: Sam Whited <sam@samwhited.com>
2 files changed, 8 insertions(+), 7 deletions(-)

M component/component.go
M component/component_test.go
M component/component.go => component/component.go +5 -5
@@ 77,17 77,17 @@ func Negotiator(addr jid.JID, secret []byte, recv bool) xmpp.Negotiator {
					foundProc = true
					continue
				}
				return mask, nil, nil, errors.New("Received unexpected proc inst from server")
				return mask, nil, nil, errors.New("component: received unexpected proc inst from server")
			case xml.StartElement:
				start = t
				break procloop
			default:
				return mask, nil, nil, errors.New("Received unexpected token from server")
				return mask, nil, nil, errors.New("component: received unexpected token from server")
			}
		}

		if start.Name.Local != "stream" || start.Name.Space != stream.NS {
			return mask, nil, nil, errors.New("Expected stream:stream from server")
			return mask, nil, nil, errors.New("component: expected stream:stream from server")
		}

		var id string


@@ 124,7 124,7 @@ func Negotiator(addr jid.JID, secret []byte, recv bool) xmpp.Negotiator {
		}
		start, ok := tok.(xml.StartElement)
		if !ok {
			return mask, nil, nil, errors.New("Expected acknowledgement or error start token from server")
			return mask, nil, nil, errors.New("component: expected acknowledgement or error start token from server")
		}

		// TODO: Actually unmarshal the stream error.


@@ 136,6 136,6 @@ func Negotiator(addr jid.JID, secret []byte, recv bool) xmpp.Negotiator {
			return xmpp.Ready | xmpp.Authn, nil, nil, err
		}

		return mask, nil, nil, fmt.Errorf("Unknown start element: %v", start)
		return mask, nil, nil, fmt.Errorf("component: unknown start element: %v", start)
	}
}

M component/component_test.go => component/component_test.go +3 -2
@@ 101,10 101,11 @@ func TestComponent(t *testing.T) {
				Writer: out,
			}, false)
			if _, ok := tc.err.(some); (ok && err == nil) || (!ok && !reflect.DeepEqual(err, tc.err)) {
				t.Fatalf("Unexpected error, got='%v' want='%v'", err, tc.err)
				t.Fatalf("unexpected error: want=%v, got=%v", tc.err, err)
			}

			if o := out.String(); len(o) < len(tc.client) || o[:len(tc.client)] != tc.client {
				t.Errorf("Unexpected output:\nGot:\n`%s`\nWant:\n`%s`\n", o, tc.client)
				t.Errorf("unexpected output:\nwant=%s\n got=%s", tc.client, o)
			}
		})
	}