|
1
|
|
|
from trifle_types import TrifleExceptionType |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
"""Internal errors. These are only used inside the interpreter and |
|
5
|
|
|
never exposed to the user. |
|
6
|
|
|
|
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class InternalError(Exception): |
|
11
|
|
|
# .message isn't available in RPython, so we manually assign it. |
|
12
|
|
|
# todo: file a pypy bug to improve their docs |
|
13
|
|
|
def __init__(self, message): |
|
14
|
|
|
assert isinstance(message, unicode) |
|
15
|
|
|
self.message = message |
|
16
|
|
|
|
|
17
|
|
|
def __str__(self): |
|
18
|
|
|
# Ignored by RPython, but useful for debugging |
|
19
|
|
|
return self.message |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
class ArityError(InternalError): |
|
23
|
|
|
pass |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class LexFailed(InternalError): |
|
27
|
|
|
pass |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
"""External errors. These may be thrown and caught by users. |
|
32
|
|
|
|
|
33
|
|
|
TODO: add CPython assertion to ensure that all TrifleExceptionType instances |
|
34
|
|
|
are defined in the global environment. |
|
35
|
|
|
|
|
36
|
|
|
""" |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
# Base exception. |
|
40
|
|
|
error = TrifleExceptionType(None, u"error") |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
stack_overflow = TrifleExceptionType(error, u"stack-overflow") |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
no_such_variable = TrifleExceptionType(error, u"no-such-variable") |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
# TODO: parse and lex errors should distinuish between bad input and |
|
50
|
|
|
# incomplete input, so our REPL knows when input is incomplete. |
|
51
|
|
|
# TODO: parse and lexing should inherit from a syntax error. |
|
52
|
|
|
parse_failed = TrifleExceptionType(error, u"parse-failed") |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
lex_failed = TrifleExceptionType(error, u"lex-failed") |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
# TODO: this name is a Pythonism, can we do better? |
|
59
|
|
|
# TODO: we need a separate index-out-of-range-error. |
|
60
|
|
|
value_error = TrifleExceptionType(error, u"value-error") |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
# TODO: we need a syntax-error too, since (try x #null) and (let (1 1)) |
|
64
|
|
|
# can be checked at compile time and don't depend on runtime types. |
|
65
|
|
|
wrong_type = TrifleExceptionType(error, u"wrong-type") |
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
wrong_argument_number = TrifleExceptionType(error, u"wrong-argument-number") |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
missing_key = TrifleExceptionType(error, u"missing-key") |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
division_by_zero = TrifleExceptionType(error, u"division-by-zero") |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
# TODO: We should group file errors into a common base exception. |
|
78
|
|
|
file_not_found = TrifleExceptionType(error, u"file-not-found") |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
# TODO: find a better name here |
|
82
|
|
|
changing_closed_handle = TrifleExceptionType(error, u"changing-closed-handle") |
|
83
|
|
|
|