Errors
tinyhgvs currently exposes one public exception type, TinyHGVSError, with a
stable broad error kind and a more specific diagnostic code.
Representative examples:
- Invalid syntax:
NM_004006.2:c.5697delA->invalid.syntax - Unsupported allele syntax:
NC_000001.11:g.[123G>A;345del]->unsupported.allele - Unsupported protein frameshift syntax:
p.(Gln576SerfsTer21)->unsupported.protein_frameshift - Unsupported RNA special-state syntax:
NM_004006.3:r.spl->unsupported.rna_special_state
Public exception types raised by :mod:tinyhgvs.
ParseHgvsErrorKind
Bases: str, Enum
Broad categories used by :class:TinyHGVSError.
Attributes:
| Name | Type | Description |
|---|---|---|
INVALID_SYNTAX |
The input does not match the currently supported HGVS grammar. |
|
UNSUPPORTED_SYNTAX |
The input belongs to a recognized HGVS family that is not supported yet. |
|
SEMANTIC_CONSTRAINT |
Reserved for future semantic validation errors after structural parsing. |
Examples:
Invalid syntax that does not match the supported grammar:
>>> from tinyhgvs import TinyHGVSError, parse_hgvs
>>> try:
... parse_hgvs("not an hgvs variant")
... except TinyHGVSError as error:
... error.kind
<ParseHgvsErrorKind.INVALID_SYNTAX: 'invalid_syntax'>
Unsupported syntax that is recognized but not implemented:
>>> try:
... parse_hgvs("NC_000001.11:g.[123G>A;345del]")
... except TinyHGVSError as error:
... error.kind
<ParseHgvsErrorKind.UNSUPPORTED_SYNTAX: 'unsupported_syntax'>
TinyHGVSError
TinyHGVSError(kind: ParseHgvsErrorKind | str, code: str, message: str, input: str, fragment: str | None, parser_version: str)
Bases: ValueError
Structured exception for tinyhgvs parse failures.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Broad error class derived from the Rust error model. |
|
code |
Stable diagnostic code such as |
|
message |
Human-readable explanation of the failure. |
|
input |
Original HGVS string that failed to parse. |
|
fragment |
Relevant unsupported fragment when one was detected. |
|
parser_version |
|
Examples:
Unsupported allele syntax:
>>> from tinyhgvs import TinyHGVSError, parse_hgvs
>>> try:
... parse_hgvs("NC_000001.11:g.[123G>A;345del]")
... except TinyHGVSError as error:
... (error.kind.value, error.code, error.fragment)
('unsupported_syntax', 'unsupported.allele', '[')
Invalid syntax:
>>> try:
... parse_hgvs("NM_004006.2:c.5697delA")
... except TinyHGVSError as error:
... (error.kind.value, error.code)
('invalid_syntax', 'invalid.syntax')
Unsupported protein frameshift syntax:
>>> try:
... parse_hgvs("p.(Gln576SerfsTer21)")
... except TinyHGVSError as error:
... (error.code, error.fragment)
('unsupported.protein_frameshift', 'fs')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
ParseHgvsErrorKind | str
|
Broad error kind. |
required |
code
|
str
|
Stable diagnostic code. |
required |
message
|
str
|
Human-readable error message. |
required |
input
|
str
|
Full HGVS string that failed. |
required |
fragment
|
str | None
|
Relevant fragment recognized by the diagnostic layer. |
required |
parser_version
|
str
|
|
required |