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 member syntax:
NM_004006.2:c.[2376G>C];[?]->unsupported.allele_unknown_variant - Unsupported uncertain allele-member state:
NM_004006.2:c.[2376G>C](;)(1083A>C)->unsupported.allele_uncertain_variant_state - Unsupported alternate allele-state syntax:
NP_003997.2:p.[(Asn158Asp)(;)(Asn158Ile)]^[(Asn158Val)]->unsupported.alternate_allele_state - Unsupported one-allele multi-protein syntax:
NP_003997.1:p.[Lys31Asn,Val25_Lys31del]->unsupported.one_allele_multi_protein - Unsupported quantified protein insertion syntax:
p.Arg78_Gly79insXaa[23]->unsupported.protein_insertion_payload - 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("NM_004006.2:c.[2376G>C];[?]")
... 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 in the format of |
|
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 variant with variant unknown:
>>> from tinyhgvs import TinyHGVSError, parse_hgvs
>>> try:
... parse_hgvs("NM_004006.2:c.[2376G>C];[?]")
... except TinyHGVSError as error:
... (error.kind.value, error.code, error.fragment)
('unsupported_syntax', 'unsupported.allele_unknown_variant', '[?]')
Invalid syntax:
>>> try:
... parse_hgvs("NM_004006.2:c.5697delA")
... except TinyHGVSError as error:
... (error.kind.value, error.code)
('invalid_syntax', 'invalid.syntax')
Unsupported quantified protein insertion syntax:
>>> try:
... parse_hgvs("p.Arg78_Gly79insXaa[23]")
... except TinyHGVSError as error:
... (error.code, error.fragment)
('unsupported.protein_insertion_payload', 'Xaa[...]')
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 |