1 | ---
|
2 | default_highlighter: oils-sh
|
3 | ---
|
4 |
|
5 | Oils Error Catalog, With Hints
|
6 | ==================
|
7 |
|
8 | This doc lists errors from Oils (both [OSH]($xref) and [YSH]($xref)), with
|
9 | hints to help you fix them.
|
10 |
|
11 | Each error is associated with a code like `OILS-ERR-42`, a string that search
|
12 | engines should find.
|
13 |
|
14 | <!--
|
15 | Later, 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 |
|
23 | If you see an error that you don't understand:
|
24 |
|
25 | 1. Ask a question on `#oil-help` on [Zulip]($xref:zulip). What's the problem,
|
26 | and what's the solution?
|
27 | 1. 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.
|
30 | 1. 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).
|
35 | 1. Optionally, add your name to the acknowledgements list at the end of this
|
36 | doc.
|
37 |
|
38 | Note that error messages are **hard** to write, because a single error could
|
39 | result from many different user **intentions**!
|
40 |
|
41 | ### To Preview this Doc
|
42 |
|
43 | Right now I use this command:
|
44 |
|
45 | build/doc.sh split-and-render doc/error-catalog.md
|
46 |
|
47 | Then 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 |
|
55 | Roughly speaking, a parse error means that text input was **rejected**, so the
|
56 | shell didn't try to do anything.
|
57 |
|
58 | Examples:
|
59 |
|
60 | echo ) # Shell syntax error
|
61 |
|
62 | type -z # -z flag not accepted
|
63 |
|
64 | These error codes start at `10`.
|
65 |
|
66 | ### OILS-ERR-10
|
67 |
|
68 | <!--
|
69 | Generated with:
|
70 | test/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 |
|
84 | Related help topics:
|
85 |
|
86 | - [setvar](ref/chap-cmd-lang.html#setvar)
|
87 |
|
88 | ### OILS-ERR-11
|
89 |
|
90 | <!--
|
91 | Generated with:
|
92 | test/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 |
|
105 | Related 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 | <!--
|
113 | Generated with:
|
114 | test/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 | - Did you to use single quotes, like `u'\n'` rather than `u"\n"`?
|
126 |
|
127 | Related help topics:
|
128 |
|
129 | - [osh-string](ref/chap-word-lang.html#osh-string) (word language)
|
130 | - [ysh-string](ref/chap-expr-lang.html#ysh-string) (expression language)
|
131 |
|
132 | ### OILS-ERR-13
|
133 |
|
134 | <!--
|
135 | Generated with:
|
136 | test/ysh-parse-errors.sh ysh_bare_words (this may move)
|
137 | -->
|
138 |
|
139 | ```
|
140 | echo \z
|
141 | ^~
|
142 | [ -c flag ]:1: Invalid char escape in unquoted word (OILS-ERR-13)
|
143 | ```
|
144 |
|
145 | - Did you mean `\\z`? Backslashes must be escaped in unquoted words.
|
146 | - Did you mean something like `\$`? Only valid escapes are accepted in YSH.
|
147 |
|
148 | ### OILS-ERR-14
|
149 |
|
150 | <!--
|
151 | Generated with:
|
152 | test/ysh-parse-errors.sh test-parse-dparen
|
153 | -->
|
154 |
|
155 | ```
|
156 | if ((1 > 0 && 43 > 42)); then echo yes; fi
|
157 | ^~
|
158 | [ -c flag ]:1: Bash (( not allowed in YSH (parse_dparen, see OILS-ERR-14 for wart)
|
159 | ```
|
160 |
|
161 | Two likely causes:
|
162 |
|
163 | - Do you need to rewrite bash arithmetic as YSH arithmetic (which is
|
164 | Python-like)?
|
165 | - Do you need to work around an [unfortunate wart](warts.html#two-left-parens-should-be-separated-by-space) in YSH?
|
166 |
|
167 | Examples:
|
168 |
|
169 | if (1 > 0 and 43 > 42) { # YSH-style
|
170 | echo yes
|
171 | }
|
172 |
|
173 | if ( (x + 1) < n) { # space between ( ( avoids ((
|
174 | echo yes
|
175 | }
|
176 |
|
177 | ### OILS-ERR-15
|
178 |
|
179 | Incorrect:
|
180 |
|
181 | # Expression mode
|
182 | if (a || b) {
|
183 | echo yes
|
184 | }
|
185 |
|
186 | # Command mode
|
187 | if test --dir a or test --dir b { ... }
|
188 |
|
189 | Correct:
|
190 |
|
191 | # Expression mode
|
192 | if (a or b) {
|
193 | echo yes
|
194 | }
|
195 |
|
196 | # Command mode
|
197 | if test --dir a || test --dir b { ... }
|
198 |
|
199 | In general, code within parentheses `()` is parsed as Python-like expressions
|
200 | -- referred to as [expression mode](command-vs-expression-mode.html). The
|
201 | standard boolean operators are written as `a and b`, `a or b` and `not a`.
|
202 |
|
203 | This differs from [command mode](command-vs-expression-mode.html) which uses
|
204 | `||` for "OR", `&&` for "AND" and `!` for "NOT".
|
205 |
|
206 | ## Runtime Errors - Traditional Shell
|
207 |
|
208 | These errors may occur in shells like [bash]($xref) and [zsh]($xref).
|
209 |
|
210 | They're numbered starting from `100`. (If we have more than 90 parse errors,
|
211 | we can start a new section, like `300`.)
|
212 |
|
213 | ### OILS-ERR-100
|
214 |
|
215 | <!--
|
216 | Generated with:
|
217 | test/runtime-errors.sh test-command-not-found
|
218 | -->
|
219 |
|
220 | ```
|
221 | findz
|
222 | ^~~~~
|
223 | [ -c flag ]:1: 'findz' not found (OILS-ERR-100)
|
224 | ```
|
225 |
|
226 | - Did you misspell a command name?
|
227 | - Did you misspell a shell function or a YSH `proc`?
|
228 | - Is the file in your `$PATH`? The `PATH` variable is a colon-separated list
|
229 | of directories, where executable files may live.
|
230 | - Is `findz` file executable bit set? (`chmod +x`)
|
231 |
|
232 | ### OILS-ERR-101
|
233 |
|
234 | <!--
|
235 | Generated with:
|
236 | test/runtime-errors.sh test-assoc-array
|
237 | -->
|
238 |
|
239 | Let's look at **three** instances of this error.
|
240 |
|
241 | ```
|
242 | declare -A assoc; assoc[x]=1
|
243 | ^~~~~~
|
244 | [ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
|
245 | ```
|
246 |
|
247 | - Is `x` a string? Then add quotes: `assoc['x']=1`
|
248 | - Is `x` a variable? Then write: `assoc[$x]=1`
|
249 |
|
250 | ---
|
251 |
|
252 | Same idea here:
|
253 |
|
254 | ```
|
255 | declare -A assoc; echo ${assoc[x]}
|
256 | ^
|
257 | [ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
|
258 | ```
|
259 |
|
260 | - Is `x` a string? Then add quotes: `${assoc['x']}`
|
261 | - Is `x` a variable? Then write: `${assoc[$x]}`
|
262 |
|
263 | ---
|
264 |
|
265 | The third example is **tricky** because `unset` takes a **string**. There's an
|
266 | extra level of parsing, which:
|
267 |
|
268 | - Implies an extra level of quoting
|
269 | - Causes OSH to display the following **nested** error message
|
270 |
|
271 | ```
|
272 | assoc[k]
|
273 | ^
|
274 | [ dynamic LHS word at line 1 of [ -c flag ] ]:1
|
275 |
|
276 | declare -A assoc; key=k; unset "assoc[$key]"
|
277 | ^
|
278 | [ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
|
279 | ```
|
280 |
|
281 | To fix it, consider using **single quotes**:
|
282 |
|
283 | unset 'assoc[$key]'
|
284 |
|
285 | ---
|
286 |
|
287 | - This is the error in [Parsing Bash is
|
288 | Undecidable](https://www.oilshell.org/blog/2016/10/20.html) (2016)
|
289 | - Also mentioned in [Known Differences](known-differences.html)
|
290 |
|
291 |
|
292 | ## Runtime Errors - Oils and YSH
|
293 |
|
294 | These errors don't occur in shells like [bash]($xref) and [zsh]($xref).
|
295 |
|
296 | They may involve Python-like **expressions** and **typed data**.
|
297 |
|
298 | They're numbered starting from `200`.
|
299 |
|
300 | ### OILS-ERR-200
|
301 |
|
302 | <!--
|
303 | Generated with:
|
304 | test/runtime-errors.sh test-external_cmd_typed_args
|
305 | -->
|
306 |
|
307 | ```
|
308 | cat ("myfile")
|
309 | ^
|
310 | [ -c flag ]:1: fatal: 'cat' appears to be external. External commands don't accept typed args (OILS-ERR-200)
|
311 | ```
|
312 |
|
313 | - Builtin commands and user-defined procs may accept [typed
|
314 | args](ref/chap-cmd-lang.html#typed-arg), but external commands never do.
|
315 | - Did you misspell a [YSH proc](ref/chap-cmd-lang.html#proc-def)? If a name is
|
316 | not found, YSH assumes it's an external command.
|
317 | - Did you forget to source a file that contains the proc or shell function you
|
318 | wanted to run?
|
319 |
|
320 | ### OILS-ERR-201
|
321 |
|
322 | <!--
|
323 | Generated with:
|
324 | test/runtime-errors.sh test-arith_ops_str
|
325 | -->
|
326 |
|
327 | ```
|
328 | = "age: " + "100"
|
329 | ^
|
330 | [ -c flag ]:1: fatal: Binary operator expected numbers, got Str and Str (OILS-ERR-201)
|
331 |
|
332 | = 100 + myvar
|
333 | ^
|
334 | [ -c flag ]:2: fatal: Binary operator expected numbers, got Int and Str (OILS-ERR-201)
|
335 | ```
|
336 |
|
337 | - Did you mean to use `++` to concatenate strings/lists?
|
338 | - The arithmetic operators [can coerce string operands to
|
339 | numbers](ref/chap-expr-lang.html#ysh-arith). However, if you are operating on
|
340 | user provided input, it may be a better idea to first parse that input with
|
341 | [`int()`](ref/chap-builtin-func.html#int) or
|
342 | [`float()`](ref/chap-builtin-func.html#float).
|
343 |
|
344 | ### OILS-ERR-202
|
345 |
|
346 | <!--
|
347 | Generated with:
|
348 | test/ysh-runtime-errors.sh test-float-equality
|
349 | -->
|
350 |
|
351 | ```
|
352 | pp (42.0 === x)
|
353 | ^~~
|
354 | [ -c flag ]:3: fatal: Equality isn't defined on Float values (OILS-ERR-202)
|
355 | ```
|
356 |
|
357 | Floating point numbers shouldn't be tested for equality. Alternatives:
|
358 |
|
359 | = abs(42.0 - x) < 0.1
|
360 | = floatEquals(42.0, x)
|
361 |
|
362 | ### OILS-ERR-203
|
363 |
|
364 | <!--
|
365 | Generated with:
|
366 | test/ysh-runtime-errors.sh test-cannot-stringify-list
|
367 | -->
|
368 |
|
369 | ```
|
370 | var mylist = [1,2,3]; write $[mylist]
|
371 | ^~
|
372 | [ -c flag ]:1: fatal: Expr sub got a List, which can't be stringified (OILS-ERR-203)
|
373 | ```
|
374 |
|
375 | - Did you mean to use `@mylist` instead of `$mylist`?
|
376 | - Did you mean to use `@[myfunc()]` instead of `$[myfunc()]`?
|
377 | - Did you mean `$[join(mylist)]`?
|
378 |
|
379 | Or:
|
380 |
|
381 | - Do you have an element that can't be stringified in a list, like `['good',
|
382 | {bad: true}]`?
|
383 |
|
384 |
|
385 | <!-- TODO -->
|
386 |
|
387 |
|
388 | ## Appendix
|
389 |
|
390 | ### Kinds of Errors from Oils
|
391 |
|
392 | - Runtime errors (status 1) - the shell tried to do something, but failed.
|
393 | - Example: `echo hi > /does/not/exist`
|
394 | - Parse errors and builtin usage errors (status 2) - input rejected, so the
|
395 | shell didn't try to do anything.
|
396 | - Uncaught I/O errors (status 2)
|
397 | - Expression errors (status 3)
|
398 | - User errors from the `error` builtin (status 10 is default)
|
399 |
|
400 | ### Contributors
|
401 |
|
402 | (If you updated this doc, feel free to add your name to the end of this list.)
|
403 |
|