Permalink
Browse files

More docs and notes about error handling.

Stub for 'set -o strict-word-eval'.
  • Loading branch information...
Andy Chu
Andy Chu committed Aug 17, 2018
1 parent 5e4025d commit 81a0851710598b8028f406021c1799bc3607a954
Showing with 79 additions and 4 deletions.
  1. +3 −1 core/state.py
  2. +76 −3 doc/errors.md
View
@@ -87,6 +87,7 @@ def Disable(self):
(None, 'strict-errexit'),
(None, 'strict-array'),
(None, 'strict-arith'),
(None, 'strict-word-eval'),
(None, 'vi'),
(None, 'emacs'),
@@ -158,7 +159,8 @@ def __init__(self, mem):
#
self.strict_arith = False # e.g. $(( x )) where x doesn't look like integer
self.strict_word = False # word splitting, etc.
#self.strict_word = False # word splitting, etc.
self.strict_word_eval = False
self.strict_scope = False # disable dynamic scope
# TODO: strict_bool. Some of this is covered by arithmetic, e.g. -eq.
View
@@ -6,27 +6,93 @@ Parse Error:
spec/parse-errors.test.sh
TODO: See test/runtime-errors.sh. Merge them here.
### Fatal vs. Non-Fatal
Fatal Error:
terminates the interpreter unconditionally, e.g. divide by zero does this in
bash.
Non-fatal error:
terminates the current builtin and exits 1
Strict modes:
Turns non-fatal errors into fatal errors.
non-fatal errors can be turned into fatal errors.
by Strict modes:
set -o errexit
Turns things that are not errors at all into fatal errors
strict modes can also things that are not errors at all into fatal errors
set -o nounset
set -o failglob
Fatal errors can be turned into non-fatal ones!!!!
by dparen:
(( 1 / 0 ))
by command sub -- although this involves another process so it's
understandable!
set -o errexit
echo $(exit 1)
### Strict Modes
strict-array
strict-errexit
strict-arith
TODO: strict-word-eval?
for unicode errors
for subshell negative indices? I think this is most consistent right now.
### Parse Error API
TODO:
p_die() internally
w = w_parser.ReadWord()
if w is None:
do something with w_parser.Error()
Related to memory management API:
# arena is the out param
arena = pool.NewArena()
c_parser = cmd_parse.CommandParser(w_parser, arena)
bool ok = c_parser.Parse()
if ok:
arena.RootNode() # turns indexes into pointers?
arena.Deallocate() # d
else:
c_parser.Error() # Is this still a stack?
### Runtime Error API: error codes + error contexts?
Idea:
- Should we have a table of errors for metaprogramming?
- assign each one of these a code, and decide what to do based on a table?
- then have an error CONTEXT
- based on spec tests?
- and error context takes an error code, looks it up in a table, and decides
whether to catch or to reraise!
List of contexts:
- assignment a=$() exit code
- command sub $()
- subshell ()
- pipeline? ls | { foo; exit 1; }
- dparen (( )) vs. arith sub $(( ))
### Problem in bash: Context affects a lot
echo $(( 1 / 0 ))
@@ -157,6 +223,13 @@ echo foo 2>& $fd
#### Builtins
In core/builtins.py:
util.usage('...')
return 1
A usage error is a runtime error that results in the builtin returning 1.
Builtin has too many arguments -- but this falls under the errexit rule
cd foo bar baz
continue "$@"

0 comments on commit 81a0851

Please sign in to comment.