Skip to content

Commit

Permalink
fixup: clever errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amnn committed Jul 11, 2024
1 parent e8fc1d3 commit 7bb12a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
25 changes: 15 additions & 10 deletions examples/tic-tac-toe/move/sources/owned.move
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,25 @@ module tic_tac_toe::owned {

// === Errors ===

/// Move was for a position that doesn't exist on the board.
const EInvalidLocation: u64 = 0;
#[error]
const EInvalidLocation: vector<u8> =
b"Move was for a position that doesn't exist on the board";

/// Game expected a move from another player.
const EWrongPlayer: u64 = 1;
#[error]
const EWrongPlayer: vector<u8> =
b"Game expected a move from another player";

/// Game has not reached an end condition.
const ENotFinished: u64 = 2;
#[error]
const ENotFinished: vector<u8> =
b"Game has not reached an end condition";

/// Can't place a mark on a finished game.
const EAlreadyFinished: u64 = 3;
#[error]
const EAlreadyFinished: vector<u8> =
b"Can't place a mark on a finished game";

/// Game reached an end state that wasn't expected.
const EInvalidEndState: u64 = 4;
#[error]
const EInvalidEndState: vector<u8> =
b"Game reached an end state that wasn't expected";

// === Public Functions ===

Expand Down
30 changes: 18 additions & 12 deletions examples/tic-tac-toe/move/sources/shared.move
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,29 @@ module tic_tac_toe::shared {

// === Errors ===

/// Move was for a position that doesn't exist on the board.
const EInvalidLocation: u64 = 0;
#[error]
const EInvalidLocation: vector<u8> =
b"Move was for a position that doesn't exist on the board.";

/// Game expected a move from another player.
const EWrongPlayer: u64 = 1;
#[error]
const EWrongPlayer: vector<u8> =
b"Game expected a move from another player";

/// Attempt to place mark on a filled slot.
const EAlreadyFilled: u64 = 2;
#[error]
const EAlreadyFilled: vector<u8> =
b"Attempted to place a mark on a filled slot.";

/// Game has not reached an end condition.
const ENotFinished: u64 = 3;
#[error]
const ENotFinished: vector<u8> =
b"Game has not reached an end condition.";

/// Can't place a mark on a finished game.
const EAlreadyFinished: u64 = 4;
#[error]
const EAlreadyFinished: vector<u8> =
b"Can't place a mark on a finished game.";

/// Game reached an end state that wasn't expected.
const EInvalidEndState: u64 = 5;
#[error]
const EInvalidEndState: vector<u8> =
b"Game reached an end state that wasn't expected.";

// === Public Functions ===

Expand Down

0 comments on commit 7bb12a4

Please sign in to comment.