37efd8463e96

Create separate error types for malformed JSON and unknown slots
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 02 Dec 2020 23:40:36 -0500
parents 6d4f34a78d74
children 558d809397bd
branches/tags (none)
files .TODO.done TODO docs/01-usage.markdown docs/02-reference.markdown docs/api.lisp docs/footer.markdown src/basic.lisp src/mop.lisp

Changes

--- 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
--- 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
--- 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
--- 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)
 
--- 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))
 
--- 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 @@
 <i>Made with Lisp and love by [Steve Losh][].</i>
 
-<p><a href="http://rochestermade.com" title="Rochester Made"><img src="https://rochestermade.com/media/images/rochester-made-dark-on-light.png" alt="Rochester Made" title="Rochester Made" /></a></p>
-
 [Steve Losh]: http://stevelosh.com/
 [roc]: https://rochestermade.com/
--- 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)
--- 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)))