Fix try/catch catches more than it should #1859

Close #1885, #2140, #2011, #2220, #2485, #2073

Rename the FORK_OPT opcode to TRY_BEGIN, add a TRY_END opcode, and wrap
errors when raising through a TRY_END so that they will not be caught by
the matching TRY_BEGIN.

Now a `try exp catch handler` expression generates code like:

    TRY_BEGIN handler
    <exp>
    TRY_END
    JUMP past_handler
    handler: <handler>
    past_handler:
    ...

On backtrack through TRY_BEGIN it just backtracks.

If anything past the whole thing raises when <exp> produced a value,
then the TRY_END will catch the error, wrap it in another, and
backtrack.  The TRY_BEGIN will see a wrapped error and then it will
unwrap and re-raise the error.

If <exp> raises, then TRY_BEGIN will catch the error and jump to the
handler, but the TRY_BEGIN will not stack_save() in that case, so on
raise/backtrack the TRY_BEGIN will not execute again (nor will the
TRY_END).
7 files changed
tree: 34c36860942562abd96156e54f32501e066840d7
  1. .github/
  2. build/
  3. config/
  4. docs/
  5. m4/
  6. modules/
  7. scripts/
  8. sig/
  9. src/
  10. tests/
  11. .gitattributes
  12. .gitignore
  13. .gitmodules
  14. AUTHORS
  15. ChangeLog
  16. compile-ios.sh
  17. configure.ac
  18. COPYING
  19. Dockerfile
  20. jq.1.prebuilt
  21. jq.spec
  22. KEYS
  23. libjq.pc.in
  24. Makefile.am
  25. NEWS
  26. README.md
  27. SECURITY.md
README.md

jq

jq is a lightweight and flexible command-line JSON processor.

If you want to learn to use jq, read the documentation at https://jqlang.github.io/jq. This documentation is generated from the docs/ folder of this repository. You can also try it online at jqplay.org.

If you want to hack on jq, feel free, but be warned that its internals are not well-documented at the moment. Bring a hard hat and a shovel. Also, read the wiki: https://github.com/jqlang/jq/wiki, where you will find cookbooks, discussion of advanced topics, internals, release engineering, and more.

Source tarball and built executable releases can be found on the homepage and on the github release page, https://github.com/jqlang/jq/releases. Docker image is available at https://github.com/jqlang/jq/pkgs/container/jq.

If you‘re building directly from the latest git, you’ll need flex, bison (3.0 or newer), libtool, make, automake, and autoconf installed. To get regexp support you'll also need to install Oniguruma or clone it as a git submodule as per the instructions below. To build, run:

git submodule update --init # if building from git to get oniguruma
autoreconf -i               # if building from git
./configure --with-oniguruma=builtin
make -j8
make check

To build without bison or flex, add --disable-maintainer-mode to the ./configure invocation:

./configure --with-oniguruma=builtin --disable-maintainer-mode

(Developers must not use --disable-maintainer-mode, not when making changes to the jq parser and/or lexer.)

To build a statically linked version of jq, run:

make LDFLAGS=-all-static

After make finishes, you'll be able to use ./jq. You can also install it using:

sudo make install

If you‘re not using the latest git version but instead building a released tarball (available on the website), then you won’t need to run autoreconf (and shouldn‘t), and you won’t need flex or bison.

To cross-compile for OS X and Windows, see docs/Rakefile‘s build task and scripts/crosscompile. You’ll need a cross-compilation environment, such as Mingw for cross-compiling for Windows.

Cross-compilation requires a clean workspace, then:

# git clean ...
autoreconf -i
./configure
make distclean
scripts/crosscompile <name-of-build> <configure-options>

Use the --host= and --target= ./configure options to select a cross-compilation environment. See also “Cross compilation” on the wiki.

To compile jq to WebAssembly, install the Emscripten SDK, then:

git submodule update --init # if building from git to get oniguruma
autoreconf -i               # if building from git
emconfigure ./configure --with-oniguruma=builtin --disable-maintainer-mode
emmake make EXEEXT=.js CFLAGS="-O2" LDFLAGS="-s EXPORTED_RUNTIME_METHODS=['callMain']"

Community