OILS / doc / ref / chap-errors.md View on Github | oilshell.org

119 lines, 77 significant
1---
2in_progress: yes
3body_css_class: width40 help-body
4default_highlighter: oils-sh
5preserve_anchor_case: yes
6---
7
8Errors
9======
10
11This chapter in the [Oils Reference](index.html) describes **errors**.
12
13Related: [Oils Error Catalog, With Hints](../error-catalog.html).
14
15<div id="toc">
16</div>
17
18
19## JSON
20
21### json-encode-err
22
23JSON encoding has three possible errors:
24
251. Object of this type can't be serialized
26 - For example, `Str List Dict` are YSH objects can be serialized.
27 - But `Eggex Func Range` can't.
281. Circular reference
29 - e.g. a Dict that points to itself, a List that points to itself, and other
30 permutations
311. Float values of NaN, Inf, and -Inf can't be encoded.
32 - TODO: option to use `null` like JavaScript.
331. Invalid UTF-8 in string, e.g. binary data like `\xfe\xff`
34 - TODO: option to use the Unicode replacement char to avoid an error.
35
36### json-decode-err
37
381. The encoded message itself is not valid UTF-8.
39 - (Typically, you need to check the unescaped bytes in string literals
40 `"abc\n"`).
411. Lexical error, like
42 - the message `+`
43 - an invalid escape `"\z"` or a truncated escape `"\u1"`
44 - A single quoted string like `u''`
451. Grammatical error
46 - like the message `}{`
471. Unexpected trailing input
48 - like the message `42]` or `{}]`
49
50## JSON8
51
52### json8-encode-err
53
54Compared to JSON, JSON8 removes an encoding error:
55
565. Invalid UTF-8 is OK, because it gets turned into a binary string like
57 `b"byte \yfe\yff"`.
58
59### json8-decode-err
60
61JSON8 has the same decoding errors as JSON, plus:
62
634. `\u{dc00}` should not be in the surrogate range. This means it doesn't
64 represent a real character, and `\yff` escapes should be used instead.
654. `\yff` should not be in `u''` string. (It's only valid in `b''` strings.)
66
67## Packle
68
69### packle-encode-err
70
71Packle has no encoding errors!
72
731. TODO: Unserializable `Eggex Func Range` can be turned into "wire Tuple"
74 `(type_name: Str, heap_id: Int)`.
75 - When you read a packle into Python, you'll get a tuple.
76 - When you read a packle back into YSH, you'll get a `value.Tombstone`?
771. Circular references are allowed. Packle data expresses a **graph**, not a
78 tree.
791. Float values NaN, Inf, and -Inf use their binary representations.
801. Both Unicode and binary data are allowed.
81
82### packle-decode-err
83
84TODO
85
86## UTF8
87
88This is for reference.
89
90### utf8-encode-err
91
92Oils stores strings as UTF-8 in memory, so it doesn't often do encoding.
93
94- Surrogate range?
95
96### utf8-decode-err
97
98#### bad-byte
99
100#### expected-start
101
102#### expected-cont
103
104#### incomplete-seq
105
106#### overlong
107
108I think this is only leading zeros?
109
110Like the difference between `123` and `0123`.
111
112#### bad-code-point
113
114e.g. decoded to something in the surrogate range
115
116Note: I think this is relaxed for WTF-8, and our JSON decoder probably needs to
117use it.
118
119