Skip to content

Commit

Permalink
refactor: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Dec 1, 2023
1 parent f3d6b3f commit ac268a8
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions go/queen-attack/queen_attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,17 @@ func CanQueenAttack(whitePosition, blackPosition string) (bool, error) {
}

func parse(position string) (location, error) {
if position == "" {
return location{}, errors.New("empty position")
}
if len(position) != 2 {
return location{}, errors.New("invalid position")
}

column := string(position[0])
row, err := strconv.Atoi(position[1:])

if err != nil {
if err != nil || !isValidRow(row) || !isValidColumn(column) {
return location{}, errors.New("invalid position")
}

if !isValidRow(row) {
return location{}, errors.New("invalid row")
}

if !isValidColumn(column) {
return location{}, errors.New("invalid column")
}

return location{row: row, column: column}, nil
}

Expand Down

0 comments on commit ac268a8

Please sign in to comment.