---
title: "ParseError"
url: https://una-lang.org/en/docs/std/prelude/ParseError/
release: v0.4.0
edition: "0.2 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/listing.json
---

# ParseError

A kind of the prelude, in scope in every module. Edition 0.2 and later.

```una
pub kind ParseError = Empty | NotADigit(at: Int) | NoDigits | TooLong
```

Why `parse_int` fails (`spec/22 §4`).

## Variants

- `Empty`: the text is empty
- `NotADigit(at)`: a character is not a digit; `at` is the scalar position\, from 0\, of the first character that is neither the leading `-` nor an ASCII digit
- `NoDigits`: the text is `-` alone
- `TooLong`: the text writes more than 4300 digits\, the sign excluded and leading zeros included

## See also

[`parse_int`](https://una-lang.org/en/docs/std/prelude/parse_int/)

## Example

`src/shop.una`

```una
module shop

--- A stock adjustment typed by hand, and why it is not one. A sign is allowed, so `-3`
--- writes off three units.
adjustment(raw: Text) -> Text
=
  let outcome = attempt parse_int(raw)
  when outcome
    is Ok(n) -> "'{raw}': adjust the stock by {n}"
    is Err(failure) -> "'{raw}': {reason(failure)}"

reason(failure: ParseError) -> Text
=
  when failure
    is Empty -> "nothing typed"
    is NoDigits -> "a sign and no digits"
    is NotADigit(at) -> "not a digit at {at}"
    is TooLong -> "more digits than an integer may have"

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print(adjustment("12"))
  @console.print(adjustment("-3"))
  @console.print(adjustment(""))
  @console.print(adjustment("-"))
  @console.print(adjustment("1x2"))
```

`una run .` prints:

```text
'12': adjust the stock by 12
'-3': adjust the stock by -3
'': nothing typed
'-': a sign and no digits
'1x2': not a digit at 1
```

## Specification

- [`spec/22 §4`](https://una-lang.org/en/docs/spec/22-text/#s4)

Generated from the standard modules of una v0.4.0 ([`docs/std/listing.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/listing.json), which is not part of the specification). The specification governs: [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1).
