OILS / doc / error-catalog.md View on Github | oilshell.org

205 lines, 142 significant
1---
2default_highlighter: oils-sh
3---
4
5Oils Error Catalog, With Hints
6==================
7
8This doc lists errors from Oils (both [OSH]($xref) and [YSH]($xref)), with
9hints to help you fix them.
10
11Each error is associated with a code like `OILS-ERR-42`, a string that search
12engines should find.
13
14<!--
15Later, we could have a URL shortener, like https://oils.err/42
16-->
17
18<div id="toc">
19</div>
20
21## How to Contribute
22
23If you see an error that you don't understand:
24
251. Ask a question on `#oil-help` on [Zulip]($xref:zulip). What's the problem,
26 and what's the solution?
271. Then `grep` the source code for the confusing error message. Tag it with a
28 string like `OILS-ERR-43`, picking a new number according to the conventions
29 below.
301. Add a tagged section below, with hints and explanations.
31 - Quote the error message. You may want copy and paste from the output of
32 `test/{parse,runtime,ysh-parse,ysh-runtime}-errors.sh`. Add an HTML
33 comment `<!-- -->` about that.
34 - Link to relevant sections in the [**Oils Reference**](ref/index.html).
351. Optionally, add your name to the acknowledgements list at the end of this
36 doc.
37
38Note that error messages are **hard** to write, because a single error could
39result from many different user **intentions**!
40
41### To Preview this Doc
42
43Right now I use this command:
44
45 build/doc.sh split-and-render doc/error-catalog.md
46
47Then paste this into your browser:
48
49 file:///home/andy/git/oilshell/oil/_release/VERSION/doc/error-catalog.html
50
51(Replace with your home dir)
52
53## Parse Errors - Rejected Input
54
55Roughly speaking, a parse error means that text input was **rejected**, so the
56shell didn't try to do anything.
57
58Examples:
59
60 echo ) # Shell syntax error
61
62 type -z # -z flag not accepted
63
64These error codes start at `10`.
65
66### OILS-ERR-10
67
68<!--
69Generated with:
70test/ysh-parse-errors.sh test-func-var-checker
71-->
72
73```
74 setvar x = true
75 ^
76[ -c flag ]:3: setvar couldn't find matching 'var x' (OILS-ERR-10)
77```
78
79- Did you forget to declare the name with the [var](ref/chap-cmd-lang.html#var)
80 keyword?
81- Did you mean to use the [setglobal](ref/chap-cmd-lang.html#setglobal)
82 keyword?
83
84Related help topics:
85
86- [setvar](ref/chap-cmd-lang.html#setvar)
87
88### OILS-ERR-11
89
90<!--
91Generated with:
92test/ysh-parse-errors.sh ysh_c_strings (this may move)
93-->
94
95```
96 echo $'\z'
97 ^
98[ -c flag ]:1: Invalid char escape in C-style string literal (OILS-ERR-11)
99```
100
101- Did you mean `$'\\z'`? Backslashes must be escaped in `$''` and `u''` and
102 `b''` strings.
103- Did you mean something like `$'\n'`? Only valid escapes are accepted in YSH.
104
105Related help topics:
106
107- [osh-string](ref/chap-word-lang.html#osh-string) (word language)
108- [ysh-string](ref/chap-expr-lang.html#ysh-string) (expression language)
109
110### OILS-ERR-12
111
112<!--
113Generated with:
114test/ysh-parse-errors.sh ysh_dq_strings (this may move)
115-->
116
117```
118 echo "\z"
119 ^
120[ -c flag ]:1: Invalid char escape in double quoted string (OILS-ERR-12)
121```
122
123- Did you mean `"\\z"`? Backslashes must be escaped in double-quoted strings.
124- Did you mean something like `"\$"`? Only valid escapes are accepted in YSH.
125
126Related help topics:
127
128- [osh-string](ref/chap-word-lang.html#osh-string) (word language)
129- [ysh-string](ref/chap-expr-lang.html#ysh-string) (expression language)
130
131### OILS-ERR-13
132
133<!--
134Generated with:
135test/ysh-parse-errors.sh ysh_bare_words (this may move)
136-->
137
138```
139 echo \z
140 ^~
141[ -c flag ]:1: Invalid char escape in unquoted word (OILS-ERR-13)
142```
143
144- Did you mean `\\z`? Backslashes must be escaped in unquoted words.
145- Did you mean something like `\$`? Only valid escapes are accepted in YSH.
146
147## Runtime Errors - Traditional Shell
148
149These errors may occur in shells like [bash]($xref) and [zsh]($xref).
150
151They're numbered starting from `100`. (If we have more than 90 parse errors,
152we can start a new section, like `300`.)
153
154### OILS-ERR-100
155
156Example TODO: Command not found.
157
158- Is the file in your `$PATH`? That variable controls where the shell shell
159 looks for executable files.
160- Did you misspell a shell function or YSH `proc`?
161
162## Runtime Errors - Oils and YSH
163
164These errors don't occur in shells like [bash]($xref) and [zsh]($xref).
165
166They may involve Python-like **expressions** and **typed data**.
167
168They're numbered starting from `200`.
169
170### OILS-ERR-200
171
172<!--
173Generated with:
174test/runtime-errors.sh test-external_cmd_typed_args
175-->
176
177```
178 cat ("myfile")
179 ^
180[ -c flag ]:1: fatal: 'cat' appears to be external. External commands don't accept typed args (OILS-ERR-200)
181```
182
183- Builtin commands and user-defined procs may accept [typed
184 args](ref/chap-cmd-lang.html#typed-arg), but external commands never do.
185- Did you misspell a [YSH proc](ref/chap-cmd-lang.html#proc-def)? If a name is
186 not found, YSH assumes it's an external command.
187- Did you forget to source a file that contains the proc or shell function you
188 wanted to run?
189
190## Appendix
191
192### Kinds of Errors from Oils
193
194- Runtime errors (status 1) - the shell tried to do something, but failed.
195 - Example: `echo hi > /does/not/exist`
196- Parse errors and builtin usage errors (status 2) - input rejected, so the
197 shell didn't try to do anything.
198- Uncaught I/O errors (status 2)
199- Expression errors (status 3)
200- User errors from the `error` builtin (status 10 is default)
201
202### Contributors
203
204(If you updated this doc, feel free to add your name to the end of this list.)
205