|
| 1 | ++++ |
| 2 | +title = "Errors and interactivity" |
| 3 | +weight = 100 |
| 4 | ++++ |
| 5 | + |
| 6 | +In all frameworks, we can choose the level of interactivity. |
| 7 | + |
| 8 | +The web framework can be interactive in different degrees. What should |
| 9 | +it do when an error happens? |
| 10 | +- not being interactive: it returns a 404 page and prints the error output on the REPL |
| 11 | +- not interactive but developper friendly: it can show the lisp error message on the HTML page, |
| 12 | +- as well as the full Lisp backtrace |
| 13 | +- it can let the developper have the interactive debugger: in that |
| 14 | + case the framework doesn't catch the error, it lets it through, and |
| 15 | + we the developper deal with it as in a normal Slime session. |
| 16 | + |
| 17 | +We see this by default: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +but we can also show backtraces and augment the data. |
| 22 | + |
| 23 | +### Hunchentoot |
| 24 | + |
| 25 | +The global variables to set are |
| 26 | +- `*show-lisp-errors-p*`, nil by default |
| 27 | +- `*show-lisp-backtraces-p*`, t by default (but the backtrace won't be shown if the previous setting is nil) |
| 28 | +- `*catch-errors-p*`, t by default, to set to `nil` to get the interactive debugger. |
| 29 | + |
| 30 | +We can see the backtrace on our error page: |
| 31 | + |
| 32 | +```lisp |
| 33 | +(setf hunchentoot:*show-lisp-errors-p* t) |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +### Enhancing the backtrace in the browser |
| 40 | + |
| 41 | +We can also the library [hunchentoot-errors](https://lisp-journey.gitlab.io/images/hunchentoot-error-with-request.png) to augment the data we see in the stacktrace: |
| 42 | + |
| 43 | +- show the **current request** (URI, headers…) |
| 44 | +- show the **current session** (everything you stored in the session) |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +## Clack errors |
| 51 | + |
| 52 | +When you use the Clack web server, you can use Clack errors, which can also show the backtrace and the session, with a colourful output: |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +### Hunchentoot's conditions |
| 57 | + |
| 58 | +Hunchentoot defines condition classes: |
| 59 | + |
| 60 | +- `hunchentoot-warning`, the superclass for all warnings |
| 61 | +- `hunchentoot-error`, the superclass for errors |
| 62 | +- `parameter-error` |
| 63 | + |
| 64 | +See the (light) documentation: [https://edicl.github.io/hunchentoot/#conditions](https://edicl.github.io/hunchentoot/#conditions). |
| 65 | + |
| 66 | +## References |
| 67 | + |
| 68 | +- [https://lisp-journey.gitlab.io/blog/common-lisp-on-the-web-enrich-your-stacktrace-with-request-and-session-data/](https://lisp-journey.gitlab.io/blog/common-lisp-on-the-web-enrich-your-stacktrace-with-request-and-session-data/) |
0 commit comments