Why Sponsor Oils? | source | all docs for version 0.22.0 | all versions | oilshell.org
This doc lists errors from Oils (both OSH and YSH), with hints to help you fix them.
Each error is associated with a code like OILS-ERR-42
, a string that search
engines should find.
If you see an error that you don't understand:
#oil-help
on Zulip. What's the problem,
and what's the solution?grep
the source code for the confusing error message. Tag it with a
string like OILS-ERR-43
, picking a new number according to the conventions
below.test/{parse,runtime,ysh-parse,ysh-runtime}-errors.sh
. Add an HTML
comment <!-- -->
about that.Note that error messages are hard to write, because a single error could result from many different user intentions!
Right now I use this command:
build/doc.sh split-and-render doc/error-catalog.md
Then paste this into your browser:
file:///home/andy/git/oilshell/oil/_release/VERSION/doc/error-catalog.html
(Replace with your home dir)
Roughly speaking, a parse error means that text input was rejected, so the shell didn't try to do anything.
Examples:
echo ) # Shell syntax error
type -z # -z flag not accepted
These error codes start at 10
.
setvar x = true
^
[ -c flag ]:3: setvar couldn't find matching 'var x' (OILS-ERR-10)
Related help topics:
echo $'\z'
^
[ -c flag ]:1: Invalid char escape in C-style string literal (OILS-ERR-11)
$'\\z'
? Backslashes must be escaped in $''
and u''
and
b''
strings.$'\n'
? Only valid escapes are accepted in YSH.Related help topics:
echo "\z"
^
[ -c flag ]:1: Invalid char escape in double quoted string (OILS-ERR-12)
"\\z"
? Backslashes must be escaped in double-quoted strings."\$"
? Only valid escapes are accepted in YSH.Related help topics:
echo \z
^~
[ -c flag ]:1: Invalid char escape in unquoted word (OILS-ERR-13)
\\z
? Backslashes must be escaped in unquoted words.\$
? Only valid escapes are accepted in YSH. if ((1 > 0 && 43 > 42)); then echo yes; fi
^~
[ -c flag ]:1: Bash (( not allowed in YSH (parse_dparen, see OILS-ERR-14 for wart)
Two likely causes:
Examples:
if (1 > 0 and 43 > 42) { # YSH-style
echo yes
}
if ( (x + 1) < n) { # space between ( ( avoids ((
echo yes
}
These errors may occur in shells like bash and zsh.
They're numbered starting from 100
. (If we have more than 90 parse errors,
we can start a new section, like 300
.)
findz
^~~~~
[ -c flag ]:1: 'findz' not found (OILS-ERR-100)
proc
?$PATH
? The PATH
variable is a colon-separated list
of directories, where executable files may live.findz
file executable bit set? (chmod +x
)Let's look at three instances of this error.
declare -A assoc; assoc[x]=1
^~~~~~
[ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
x
a string? Then add quotes: assoc['x']=1
x
a variable? Then write: assoc[$x]=1
Same idea here:
declare -A assoc; echo ${assoc[x]}
^
[ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
x
a string? Then add quotes: ${assoc['x']}
x
a variable? Then write: ${assoc[$x]}
The third example is tricky because unset
takes a string. There's an
extra level of parsing, which:
assoc[k]
^
[ dynamic LHS word at line 1 of [ -c flag ] ]:1
declare -A assoc; key=k; unset "assoc[$key]"
^
[ -c flag ]:1: fatal: Assoc array keys must be strings: $x 'x' "$x" etc. (OILS-ERR-101)
To fix it, consider using single quotes:
unset 'assoc[$key]'
These errors don't occur in shells like bash and zsh.
They may involve Python-like expressions and typed data.
They're numbered starting from 200
.
cat ("myfile")
^
[ -c flag ]:1: fatal: 'cat' appears to be external. External commands don't accept typed args (OILS-ERR-200)
= "age: " + "100"
^
[ -c flag ]:1: fatal: Binary operator expected numbers, got Str and Str (OILS-ERR-201)
= 100 + myvar
^
[ -c flag ]:2: fatal: Binary operator expected numbers, got Int and Str (OILS-ERR-201)
++
to concatenate strings/lists?int()
or
float()
. pp (42.0 === x)
^~~
[ -c flag ]:3: fatal: Equality isn't defined on Float values (OILS-ERR-202)
Floating point numbers shouldn't be tested for equality. Alternatives:
= abs(42.0 - x) < 0.1
= floatEquals(42.0, x)
echo hi > /does/not/exist
error
builtin (status 10 is default)(If you updated this doc, feel free to add your name to the end of this list.)