Commit a3f6988b authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Add codes to error messages, make group names unique. Merge #49

parent 14cbcc78
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p

### Changed
- The build system now strips up to current dir in recorded source file paths at compile.
- Addition of specific error messages to the Error payload.
- Group names must be unique.

### Fixed
- Fix regression loading config file.
+2 −2
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
CREATE TABLE IF NOT EXISTS users (
    PRIMARY KEY (id),
    id             BYTEA         NOT NULL,
    handle         VARCHAR(20)   UNIQUE NOT NULL,
    handle         VARCHAR(20)   CONSTRAINT users_handle_key UNIQUE NOT NULL,
    fullname       VARCHAR(70),
    avatar_url     VARCHAR(255),
    -- https://tools.ietf.org/html/bcp47
@@ -77,7 +77,7 @@ CREATE TABLE IF NOT EXISTS groups (
    PRIMARY KEY (id),
    id            BYTEA         NOT NULL,
    creator_id    BYTEA         NOT NULL,
    name          VARCHAR(70)   NOT NULL,
    name          VARCHAR(70)   CONSTRAINT groups_name_key UNIQUE NOT NULL,
    description   VARCHAR(255),
    avatar_url    VARCHAR(255),
    -- https://tools.ietf.org/html/bcp47
+1 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ CREATE TABLE IF NOT EXISTS leaderboard_record (
    ranked_at          INT          CHECK (ranked_at >= 0) DEFAULT 0 NOT NULL,
    updated_at         INT          CHECK (updated_at > 0) NOT NULL,
    -- Used to enable proper order in revscan when sorting by score descending.
    -- Revscan is unaviodable here due to cockroachdb/cockroach#14241.
    updated_at_inverse INT          CHECK (updated_at > 0) NOT NULL,
    expires_at         INT          CHECK (expires_at >= 0) DEFAULT 0 NOT NULL,
    banned_at          INT          CHECK (expires_at >= 0) DEFAULT 0 NOT NULL
+20 −3
Original line number Diff line number Diff line
@@ -22,7 +22,23 @@ message Heartbeat {
}

message Error {
  string reason = 1;
  enum Code {
    RUNTIME_EXCEPTION = 0;
    UNRECOGNIZED_PAYLOAD = 1;
    MISSING_PAYLOAD = 2;
    BAD_INPUT = 3;
    AUTH_ERROR = 4;
    USER_LINK_INUSE = 5;
    USER_LINK_PROVIDER_UNAVAILABLE = 6;
    USER_UNLINK_DISALLOWED = 7;
    USER_HANDLE_INUSE = 8;
    GROUP_NAME_INUSE = 9;
    STORAGE_FETCH_DISALLOWED = 10;
    MATCH_NOT_FOUND = 11;
  }

  int32 code = 1;
  string message = 2;
}

message AuthenticateRequest {
@@ -58,8 +74,9 @@ message AuthenticateResponse {
  }

  message Error {
    string reason = 1;
    AuthenticateRequest request = 2;
    int32 code = 1;
    string message = 2;
    AuthenticateRequest request = 3;
  }

  string collation_id = 1;
+19 −2
Original line number Diff line number Diff line
@@ -134,8 +134,25 @@ func (p *pipeline) processRequest(logger zap.Logger, session *session, envelope
		p.leaderboardRecordsList(logger, session, envelope)

	case nil:
		session.Send(&Envelope{CollationId: envelope.CollationId, Payload: &Envelope_Error{&Error{Reason: "No payload found"}}})
		session.Send(ErrorMessage(envelope.CollationId, MISSING_PAYLOAD, "No payload found"))
	default:
		session.Send(&Envelope{CollationId: envelope.CollationId, Payload: &Envelope_Error{&Error{Reason: "Unrecognized payload"}}})
		session.Send(ErrorMessage(envelope.CollationId, UNRECOGNIZED_PAYLOAD, "Unrecognized payload"))
	}
}

func ErrorMessageRuntimeException(collationID string, message string) *Envelope {
	return ErrorMessage(collationID, RUNTIME_EXCEPTION, message)
}

func ErrorMessageBadInput(collationID string, message string) *Envelope {
	return ErrorMessage(collationID, BAD_INPUT, message)
}

func ErrorMessage(collationID string, code Error_Code, message string) *Envelope {
	return &Envelope{
		CollationId: collationID,
		Payload: &Envelope_Error{&Error{
			Message: message,
			Code:    int32(code),
		}}}
}
Loading