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 | `doc/error-catalog.sh`, or
|
33 | `test/{parse,runtime,ysh-parse,ysh-runtime}-errors.sh`. Add an HTML
|
34 | comment `<!-- -->` about that.
|
35 | - Link to relevant sections in the [**Oils Reference**](ref/index.html).
|
36 | 1. Optionally, add your name to the acknowledgements list at the end of this
|
37 | doc.
|
38 |
|
39 | Note that error messages are **hard** to write, because a single error could
|
40 | result from many different user **intentions**!
|
41 |
|
42 | ### To Preview this Doc
|
43 |
|
44 | Right now I use this command:
|
45 |
|
46 | build/doc.sh split-and-render doc/error-catalog.md
|
47 |
|
48 | Then paste this into your browser:
|
49 |
|
50 | file:///home/andy/git/oilshell/oil/_release/VERSION/doc/error-catalog.html
|
51 |
|
52 | (Replace with your home dir)
|
53 |
|
54 | ## Parse Errors - Rejected Input
|
55 |
|
56 | Roughly speaking, a parse error means that text input was **rejected**, so the
|
57 | shell didn't try to do anything.
|
58 |
|
59 | Examples:
|
60 |
|
61 | echo ) # Shell syntax error
|
62 |
|
63 | type -z # -z flag not accepted
|
64 |
|
65 | These error codes start at `10`.
|
66 |
|
67 | ### OILS-ERR-10
|
68 |
|
69 | <!--
|
70 | Generated with:
|
71 | test/ysh-parse-errors.sh test-func-var-checker
|
72 | -->
|
73 |
|
74 | ```
|
75 | setvar x = true
|
76 | ^
|
77 | [ -c flag ]:3: setvar couldn't find matching 'var x' (OILS-ERR-10)
|
78 | ```
|
79 |
|
80 | - Did you forget to declare the name with the [var](ref/chap-ysh-cmd.html#var)
|
81 | keyword?
|
82 | - Did you mean to use the [setglobal](ref/chap-ysh-cmd.html#setglobal)
|
83 | keyword?
|
84 |
|
85 | Related help topics:
|
86 |
|
87 | - [setvar](ref/chap-ysh-cmd.html#setvar)
|
88 |
|
89 | ### OILS-ERR-11
|
90 |
|
91 | <!--
|
92 | Generated with:
|
93 | test/ysh-parse-errors.sh ysh_c_strings (this may move)
|
94 | -->
|
95 |
|
96 | ```
|
97 | echo $'\z'
|
98 | ^
|
99 | [ -c flag ]:1: Invalid char escape in C-style string literal (OILS-ERR-11)
|
100 | ```
|
101 |
|
102 | - Did you mean `$'\\z'`? Backslashes must be escaped in `$''` and `u''` and
|
103 | `b''` strings.
|
104 | - Did you mean something like `$'\n'`? Only valid escapes are accepted in YSH.
|
105 |
|
106 | Related help topics:
|
107 |
|
108 | - [osh-string](ref/chap-word-lang.html#osh-string) (word language)
|
109 | - [ysh-string](ref/chap-expr-lang.html#ysh-string) (expression language)
|
110 |
|
111 | ### OILS-ERR-12
|
112 |
|
113 | <!--
|
114 | Generated with:
|
115 | test/ysh-parse-errors.sh ysh_dq_strings (this may move)
|
116 | -->
|
117 |
|
118 | ```
|
119 | echo "\z"
|
120 | ^
|
121 | [ -c flag ]:1: Invalid char escape in double quoted string (OILS-ERR-12)
|
122 | ```
|
123 |
|
124 | - Did you mean `"\\z"`? Backslashes must be escaped in double-quoted strings.
|
125 | - Did you mean something like `"\$"`? Only valid escapes are accepted in YSH.
|
126 | - Did you to use single quotes, like `u'\n'` rather than `u"\n"`?
|
127 |
|
128 | Related help topics:
|
129 |
|
130 | - [osh-string](ref/chap-word-lang.html#osh-string) (word language)
|
131 | - [ysh-string](ref/chap-expr-lang.html#ysh-string) (expression language)
|
132 |
|
133 | ### OILS-ERR-13
|
134 |
|
135 | <!--
|
136 | Generated with:
|
137 | test/ysh-parse-errors.sh ysh_bare_words (this may move)
|
138 | -->
|
139 |
|
140 | ```
|
141 | echo \z
|
142 | ^~
|
143 | [ -c flag ]:1: Invalid char escape in unquoted word (OILS-ERR-13)
|
144 | ```
|
145 |
|
146 | - Did you mean `\\z`? Backslashes must be escaped in unquoted words.
|
147 | - Did you mean something like `\$`? Only valid escapes are accepted in YSH.
|
148 |
|
149 | ### OILS-ERR-14
|
150 |
|
151 | <!--
|
152 | Generated with:
|
153 | test/ysh-parse-errors.sh test-parse-dparen
|
154 | -->
|
155 |
|
156 | ```
|
157 | if ((1 > 0 && 43 > 42)); then echo yes; fi
|
158 | ^~
|
159 | [ -c flag ]:1: Bash (( not allowed in YSH (parse_dparen, see OILS-ERR-14 for wart)
|
160 | ```
|
161 |
|
162 | Two likely causes:
|
163 |
|
164 | - Do you need to rewrite bash arithmetic as YSH arithmetic (which is
|
165 | Python-like)?
|
166 | - Do you need to work around an [unfortunate wart](warts.html#two-left-parens-should-be-separated-by-space) in YSH?
|
167 |
|
168 | Examples:
|
169 |
|
170 | if (1 > 0 and 43 > 42) { # YSH-style
|
171 | echo yes
|
172 | }
|
173 |
|
174 | if ( (x + 1) < n) { # space between ( ( avoids ((
|
175 | echo yes
|
176 | }
|
177 |
|
178 | ### OILS-ERR-15
|
179 |
|
180 | ```
|
181 | if (a || b && c) {
|
182 | ^~
|
183 | [ -c flag ]:2: Use 'or' in expression mode (OILS-ERR-15)
|
184 | ```
|
185 |
|
186 | Expression mode uses `not or and`, rather than `! || &&`. See [Command vs.
|
187 | Expression Mode](command-vs-expression-mode.html) for details.
|
188 |
|
189 |
|
190 | No:
|
191 |
|
192 | if (!a || b && c) {
|
193 | echo no
|
194 | }
|
195 |
|
196 | Yes:
|
197 |
|
198 | if (not a or b and c) {
|
199 | echo yes
|
200 | }
|
201 |
|
202 |
|
203 | Command mode is the opposite; it uses `! || &&`, rather than `not or and`:
|
204 |
|
205 | No:
|
206 |
|
207 | # Command mode
|
208 | if not test --dir a or test --dir b and test --dir c {
|
209 | echo no
|
210 | }
|
211 |
|
212 | Yes:
|
213 |
|
214 | # Command mode
|
215 | if ! test --dir a || test --dir b && test --dir c {
|
216 | echo yes
|
217 | }
|
218 |
|
219 | ### OILS-ERR-16
|
220 |
|
221 | ```
|
222 | for x in (1 .. 5) {
|
223 | ^~
|
224 | [ -c flag ]:1: Use ..< for half-open range, or ..= for closed range (OILS-ERR-16)
|
225 | ```
|
226 |
|
227 | <!--
|
228 | Similar to
|
229 | test/ysh-parse-errors.sh test-expr-range
|
230 | -->
|
231 |
|
232 | There are two ways to construct a [Range](ref/chap-expr-lang#range). The `..<`
|
233 | operator is for half-open ranges and the `..=` operator is for closed ranges:
|
234 |
|
235 | for i in (0 ..< 3) {
|
236 | echo $i
|
237 | }
|
238 | => 0
|
239 | => 1
|
240 | => 2
|
241 |
|
242 | for i in (0 ..= 3) {
|
243 | echo $i
|
244 | }
|
245 | => 0
|
246 | => 1
|
247 | => 2
|
248 | => 3
|
249 |
|
250 | ## Runtime Errors - Traditional Shell
|
251 |
|
252 | These errors may occur in shells like [bash]($xref) and [zsh]($xref).
|
253 |
|
254 | They're numbered starting from `100`. (If we have more than 90 parse errors,
|
255 | we can start a new section, like `300`.)
|
256 |
|
257 | ### OILS-ERR-100
|
258 |
|
259 | <!--
|
260 | Generated with:
|
261 | test/runtime-errors.sh test-command-not-found
|
262 | -->
|
263 |
|
264 | ```
|
265 | findz
|
266 | ^~~~~
|
267 | [ -c flag ]:1: 'findz' not found (OILS-ERR-100)
|
268 | ```
|
269 |
|
270 | - Did you misspell a command name?
|
271 | - Did you misspell a shell function or a YSH `proc`?
|
272 | - Is the file in your `$PATH`? The `PATH` variable is a colon-separated list
|
273 | of directories, where executable files may live.
|
274 | - Is `findz` file executable bit set? (`chmod +x`)
|
275 |
|
276 | ### OILS-ERR-101
|
277 |
|
278 | <!--
|
279 | Generated with:
|
280 | test/runtime-errors.sh test-assoc-array
|
281 | -->
|
282 |
|
283 | Let's look at **three** instances of this error.
|
284 |
|
285 | ```
|
286 | declare -A assoc; assoc[x]=1
|
287 | ^~~~~~
|
288 | [ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
|
289 | ```
|
290 |
|
291 | - Is `x` a string? Then add quotes: `assoc['x']=1`
|
292 | - Is `x` a variable? Then write: `assoc[$x]=1`
|
293 |
|
294 | ---
|
295 |
|
296 | Same idea here:
|
297 |
|
298 | ```
|
299 | declare -A assoc; echo ${assoc[x]}
|
300 | ^
|
301 | [ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
|
302 | ```
|
303 |
|
304 | - Is `x` a string? Then add quotes: `${assoc['x']}`
|
305 | - Is `x` a variable? Then write: `${assoc[$x]}`
|
306 |
|
307 | ---
|
308 |
|
309 | The third example is **tricky** because `unset` takes a **string**. There's an
|
310 | extra level of parsing, which:
|
311 |
|
312 | - Implies an extra level of quoting
|
313 | - Causes OSH to display the following **nested** error message
|
314 |
|
315 | ```
|
316 | assoc[k]
|
317 | ^
|
318 | [ dynamic LHS word at line 1 of [ -c flag ] ]:1
|
319 |
|
320 | declare -A assoc; key=k; unset "assoc[$key]"
|
321 | ^
|
322 | [ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
|
323 | ```
|
324 |
|
325 | To fix it, consider using **single quotes**:
|
326 |
|
327 | unset 'assoc[$key]'
|
328 |
|
329 | ---
|
330 |
|
331 | - This is the error in [Parsing Bash is
|
332 | Undecidable](https://www.oilshell.org/blog/2016/10/20.html) (2016)
|
333 | - Also mentioned in [Known Differences](known-differences.html)
|
334 |
|
335 |
|
336 | ## Runtime Errors - Oils and YSH
|
337 |
|
338 | These errors don't occur in shells like [bash]($xref) and [zsh]($xref).
|
339 |
|
340 | They may involve Python-like **expressions** and **typed data**.
|
341 |
|
342 | They're numbered starting from `200`.
|
343 |
|
344 | ### OILS-ERR-200
|
345 |
|
346 | <!--
|
347 | Generated with:
|
348 | test/runtime-errors.sh test-external_cmd_typed_args
|
349 | -->
|
350 |
|
351 | ```
|
352 | cat ("myfile")
|
353 | ^
|
354 | [ -c flag ]:1: fatal: 'cat' appears to be external. External commands don't accept typed args (OILS-ERR-200)
|
355 | ```
|
356 |
|
357 | - Builtin commands and user-defined procs may accept [typed
|
358 | args](ref/chap-cmd-lang.html#typed-arg), but external commands never do.
|
359 | - Did you misspell a [YSH proc](ref/chap-cmd-lang.html#proc-def)? If a name is
|
360 | not found, YSH assumes it's an external command.
|
361 | - Did you forget to source a file that contains the proc or shell function you
|
362 | wanted to run?
|
363 |
|
364 | ### OILS-ERR-201
|
365 |
|
366 | <!--
|
367 | Generated with:
|
368 | test/runtime-errors.sh test-arith_ops_str
|
369 | -->
|
370 |
|
371 | ```
|
372 | = "age: " + "100"
|
373 | ^
|
374 | [ -c flag ]:1: fatal: Binary operator expected numbers, got Str and Str (OILS-ERR-201)
|
375 |
|
376 | = 100 + myvar
|
377 | ^
|
378 | [ -c flag ]:2: fatal: Binary operator expected numbers, got Int and Str (OILS-ERR-201)
|
379 | ```
|
380 |
|
381 | - Did you mean to use `++` to concatenate strings/lists?
|
382 | - The arithmetic operators [can coerce string operands to
|
383 | numbers](ref/chap-expr-lang.html#ysh-arith). However, if you are operating on
|
384 | user provided input, it may be a better idea to first parse that input with
|
385 | [`int()`](ref/chap-builtin-func.html#int) or
|
386 | [`float()`](ref/chap-builtin-func.html#float).
|
387 |
|
388 | ### OILS-ERR-202
|
389 |
|
390 | <!--
|
391 | Generated with:
|
392 | test/ysh-runtime-errors.sh test-float-equality
|
393 | -->
|
394 |
|
395 | ```
|
396 | pp (42.0 === x)
|
397 | ^~~
|
398 | [ -c flag ]:3: fatal: Equality isn't defined on Float values (OILS-ERR-202)
|
399 | ```
|
400 |
|
401 | Floating point numbers shouldn't be tested for equality. Alternatives:
|
402 |
|
403 | = abs(42.0 - x) < 0.1
|
404 | = floatEquals(42.0, x)
|
405 |
|
406 | ### OILS-ERR-203
|
407 |
|
408 | <!--
|
409 | Generated with:
|
410 | test/ysh-runtime-errors.sh test-cannot-stringify-list
|
411 | -->
|
412 |
|
413 | ```
|
414 | var mylist = [1,2,3]; write $[mylist]
|
415 | ^~
|
416 | [ -c flag ]:1: fatal: Expr sub got a List, which can't be stringified (OILS-ERR-203)
|
417 | ```
|
418 |
|
419 | - Did you mean to use `@mylist` instead of `$mylist`?
|
420 | - Did you mean to use `@[myfunc()]` instead of `$[myfunc()]`?
|
421 | - Did you mean `$[join(mylist)]`?
|
422 |
|
423 | Or:
|
424 |
|
425 | - Do you have an element that can't be stringified in a list, like `['good',
|
426 | {bad: true}]`?
|
427 |
|
428 |
|
429 | <!-- TODO -->
|
430 |
|
431 | ## Runtime Errors: `strict:all`
|
432 |
|
433 | ### OILS-ERR-300
|
434 |
|
435 | ```
|
436 | if ! ls | wc -l; then echo failed; fi
|
437 | ^
|
438 | [ -c flag ]:1: fatal: Command conditionals should only have one status, not Pipeline (strict_errexit, OILS-ERR-300)
|
439 | ```
|
440 |
|
441 | Compound commands can't be used as conditionals because it's ambiguous.
|
442 |
|
443 | It confuses true/false with pass/fail. What if part of the pipeline fails?
|
444 | What if `ls` doesn't exist?
|
445 |
|
446 | This YSH idiom is more explicit:
|
447 |
|
448 | try {
|
449 | ls | wc -l
|
450 | }
|
451 | if failed {
|
452 | echo failed
|
453 | }
|
454 |
|
455 | ## Appendix
|
456 |
|
457 | ### Kinds of Errors from Oils
|
458 |
|
459 | - Runtime errors (status 1) - the shell tried to do something, but failed.
|
460 | - Example: `echo hi > /does/not/exist`
|
461 | - Parse errors and builtin usage errors (status 2) - input rejected, so the
|
462 | shell didn't try to do anything.
|
463 | - Uncaught I/O errors (status 2)
|
464 | - Expression errors (status 3)
|
465 | - User errors from the `error` builtin (status 10 is default)
|
466 |
|
467 | ### Contributors
|
468 |
|
469 | (If you updated this doc, feel free to add your name to the end of this list.)
|
470 |
|