Software / code / prosody
Comparison
util/serialization.lua @ 9570:ce403b6470f8
util.serialization: Encode non-fatal error in way that can be restored
It could previously encode to eg `{ [nil] = ... }` which doesn't get decoded
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 27 Oct 2018 12:56:01 +0200 |
| parent | 9569:0bc399953c27 |
| child | 9692:affcbccc1dff |
| child | 10060:7a36b7ac309b |
comparison
equal
deleted
inserted
replaced
| 9569:0bc399953c27 | 9570:ce403b6470f8 |
|---|---|
| 37 local function fatal_error(obj, why) | 37 local function fatal_error(obj, why) |
| 38 error("Can't serialize "..type(obj) .. (why and ": ".. why or "")); | 38 error("Can't serialize "..type(obj) .. (why and ": ".. why or "")); |
| 39 end | 39 end |
| 40 | 40 |
| 41 local function nonfatal_fallback(x, why) | 41 local function nonfatal_fallback(x, why) |
| 42 return s_format("nil --[[%s: %s]]", type(x), why or "fail"); | 42 return s_format("{__type=%q,__error=%q}", type(x), why or "fail"); |
| 43 end | 43 end |
| 44 | 44 |
| 45 local string_escapes = { | 45 local string_escapes = { |
| 46 ['\a'] = [[\a]]; ['\b'] = [[\b]]; | 46 ['\a'] = [[\a]]; ['\b'] = [[\b]]; |
| 47 ['\f'] = [[\f]]; ['\n'] = [[\n]]; | 47 ['\f'] = [[\f]]; ['\n'] = [[\n]]; |