google / google/jsonnet

Consider try / catch functionality

Open
#415 8 comments 5 reactions 0 assignees View on GitHub
enhancement
Dominant language
Jsonnet
Stars
7.6k
Forks
475
PR merge metrics
No merged PRs in 30d

Description

Currently `error "foo"` is like throwing an exception, but there is no way to catch the exception.

Motivations for "catch":
1) Routines that loop over data and trigger errors for particular items don't have useful stack traces because the line of code in the stack trace doesn't tell you e.g. which array index caused the problem. This is particularly important in custom manifestation functions where we typically iterate over the tree forcing fields.
2) It is currently not possible to write test cases in Jsonnet that check that the correct error is raised.
3) It is not possible to detect using reflection that a field requires overriding, because we typically represent that with `f: error "Must overide f"` see #414.

Caveats:
- Should it be possible to catch "runtime errors" like `1/0` or `[1,2,3][10]`? If not, how do we distinguish?
- Should it be possible to catch major errors like exceeding stack size? If not, how do we distinguish?
- It is clearly not possible to catch non-termination (halting problem).
- Should error values be cached in thunks?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.