# HG changeset patch # User Steve Losh # Date 1606970436 18000 # Node ID 37efd8463e96906045ef5129b2f8ebe0a99dc1b2 # Parent 6d4f34a78d74a63e1f42675384f71ed944e27d75 Create separate error types for malformed JSON and unknown slots diff -r 6d4f34a78d74 -r 37efd8463e96 .TODO.done --- a/.TODO.done Tue Dec 01 01:18:18 2020 -0500 +++ b/.TODO.done Wed Dec 02 23:40:36 2020 -0500 @@ -1,6 +1,7 @@ Indentation. | id:0184922ad2c249da5361f439f6449fadcb27d43c Add read/print disabling mechanism | id:1268bf0b10c13aec23aafbd8f5e236db1e485fa5 Fix :allow-print and :allow-read to set t when removing them during class redef. | id:21cce1bed829a138de33b33e3ad3219f7888be04 +Clean up error hierarchy | id:3d3efa4af649474151661a9d294080ab24e22ff7 Input wrapping. | id:7bc7f71a7dd85e13efde40b5ea2a5b6bfe13cf58 Add basic wrapper definition | id:861f048b3b69079dedf8779be1cb73c05e6fc732 Optimize discarding | id:93105ef9d21d33bfb10c67fcac36bc60434d3fb4 diff -r 6d4f34a78d74 -r 37efd8463e96 TODO --- a/TODO Tue Dec 01 01:18:18 2020 -0500 +++ b/TODO Wed Dec 02 23:40:36 2020 -0500 @@ -1,4 +1,3 @@ -Clean up error hierarchy | id:3d3efa4af649474151661a9d294080ab24e22ff7 Write documentation. | id:8612eacd92edd0b4b196feb5d084d58e86cedeeb Fuzz against other JSON implementations | id:ccfe488e219c9454228a0510c61f8c59946e5875 Ensure slots are coalesced properly. | id:d800e6516a5bf5f8ce843f442956078e7a1b672e diff -r 6d4f34a78d74 -r 37efd8463e96 docs/01-usage.markdown --- a/docs/01-usage.markdown Tue Dec 01 01:18:18 2020 -0500 +++ b/docs/01-usage.markdown Wed Dec 02 23:40:36 2020 -0500 @@ -7,3 +7,47 @@ [TOC] +Generic JSON +------------ + +### Reading +### Printing + +Specifying JSON Types +--------------------- + +Parsing Without Allocation (TODO: better title) +----------------------------------------------- + +Limits and Errors +----------------- + +MOP JSON +-------- + +Inheritance +----------- + +Allow Print/Read +---------------- + +Unknown Slot Handling +--------------------- + +Input Struct (TODO better title) +-------------------------------- + +Wrapping Existing Classes +------------------------- + +Simple way, using after-read and before-print. + +End-user way, using wrappers. Emphasize that this is *not* to be used in +libraries. + +Other JSON Implementations +-------------------------- + +json-mop + +yason, jonathon, etc diff -r 6d4f34a78d74 -r 37efd8463e96 docs/02-reference.markdown --- a/docs/02-reference.markdown Tue Dec 01 01:18:18 2020 -0500 +++ b/docs/02-reference.markdown Wed Dec 02 23:40:36 2020 -0500 @@ -12,7 +12,7 @@ ## Package `JARL` -### `JSON-PARSING-ERROR` (class) +### `JSON-READING-ERROR` (class) ### `PRINT` (function) @@ -20,5 +20,5 @@ ### `READ` (function) - (READ CLASS-DESIGNATOR STREAM-OR-STRING &OPTIONAL (EOF-ERROR-P T) EOF) + (READ CLASS-DESIGNATOR INPUT &OPTIONAL (EOF-ERROR-P T) EOF) diff -r 6d4f34a78d74 -r 37efd8463e96 docs/api.lisp --- a/docs/api.lisp Tue Dec 01 01:18:18 2020 -0500 +++ b/docs/api.lisp Wed Dec 02 23:40:36 2020 -0500 @@ -22,10 +22,13 @@ "docs/static/errors.svg" '(jarl::json-error jarl::json-reading-error + jarl::malformed-json-error + jarl::unknown-json-slot-error jarl::json-limit-exceeded-error jarl::json-size-limit-exceeded-error jarl::json-depth-limit-exceeded-error) :abstract-classes '(jarl::json-error + jarl::json-reading-error jarl::json-limit-exceeded-error)) diff -r 6d4f34a78d74 -r 37efd8463e96 docs/footer.markdown --- a/docs/footer.markdown Tue Dec 01 01:18:18 2020 -0500 +++ b/docs/footer.markdown Wed Dec 02 23:40:36 2020 -0500 @@ -1,6 +1,4 @@ Made with Lisp and love by [Steve Losh][]. -

Rochester Made

- [Steve Losh]: http://stevelosh.com/ [roc]: https://rochestermade.com/ diff -r 6d4f34a78d74 -r 37efd8463e96 src/basic.lisp --- a/src/basic.lisp Tue Dec 01 01:18:18 2020 -0500 +++ b/src/basic.lisp Wed Dec 02 23:40:36 2020 -0500 @@ -92,6 +92,12 @@ (column c) (message c))))) +(define-condition malformed-json-error (json-reading-error) + ()) + +(define-condition unknown-json-slot-error (json-reading-error) + ((name :accessor name :initarg :name))) + (define-condition json-limit-exceeded-error (json-reading-error) ((limit :accessor limit :initarg :limit) (limit-name :allocation :class)) @@ -111,7 +117,7 @@ (defun e (class input format-string &rest args) ; error - (error 'json-reading-error + (error 'malformed-json-error :class-designator class :line (input-line input) :column (input-column input) diff -r 6d4f34a78d74 -r 37efd8463e96 src/mop.lisp --- a/src/mop.lisp Tue Dec 01 01:18:18 2020 -0500 +++ b/src/mop.lisp Wed Dec 02 23:40:36 2020 -0500 @@ -184,6 +184,7 @@ ;;;; Read --------------------------------------------------------------------- + (defun parse-json-class (class-name class input) (unless (allow-read class) (error "Class ~S does not allow reading." class)) @@ -210,7 +211,12 @@ (:preserve (setf (gethash name (or preserved (setf preserved (make-hash-table :test #'equal)))) (read% t nil input))) (:discard (read% nil nil input)) - (:error (e class-name input "got unknown object attribute ~S" name))) + (:error (error 'unknown-json-slot-error + :class-designator class-name + :line (input-line input) + :column (input-column input) + :name name + :message (format nil "unknown object attribute ~S" name)))) (let ((value (read% c cc input))) (push (if after-read (funcall after-read value) value) init) (push initarg init)))