Skip to content

Commit

Permalink
Document custom error types
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Oct 16, 2024
1 parent c9749dc commit 62a1bb9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lenient_parse.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,32 @@ pub fn to_int(text: String) -> Result(Int, ParseError) {
}

pub type ParseError {
/// Represents an error when an invalid character is encountered during
/// parsing. The `String` parameter contains the invalid character.
InvalidCharacter(String)

/// Represents an error when the input string is empty or contains only
/// whitespace.
WhitespaceOnlyOrEmptyString

/// Represents an error when an underscore is in an invalid position within
/// the number string.
InvalidUnderscorePosition

/// Represents an error when a decimal point is in an invalid position within
/// the number string.
InvalidDecimalPosition

/// Represents an error that occurs when Gleam's built-in `float.parse` fails
/// after our custom lenient parsing steps. This indicates that even with our
/// more permissive parsing rules, the string still couldn't be converted to a
/// float.
GleamFloatParseError

/// Represents an error that occurs when Gleam's built-in `int.parse` fails
/// after our custom lenient parsing steps. This indicates that even with our
/// more permissive parsing rules, the string still couldn't be converted to
/// an integer.
GleamIntParseError
}

Expand Down

0 comments on commit 62a1bb9

Please sign in to comment.