quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Unhelpful error message when schema JSON is invalid

Open schani opened this issue 6 years ago • 4 comments

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/foo",
  "definitions": {
    "foo": {
      "type": "object",
      "properties": {
        "bar": {
          "$ref": "bar.json#"
        },
      },
      "required": [
        "bar"
      ],
    },
    "title": "foo"
  }
}

Running quicktype CLI with this Schema produces

Error: Internal error: Defined value expected, but got undefined.

schani avatar Sep 11 '18 15:09 schani

Let me see how I can help.

Armaxxx avatar Dec 15 '20 01:12 Armaxxx

I tried running the above schema with quick type. On my machine it gives a helpful message. To be exact it outputs :

$ quicktype test.json
Error: Syntax error in input JSON test: Parser cannot parse input: unexpected token '}'.

I think that is pretty valid output. Though providing the line number and column will be pretty good

ps173 avatar Oct 02 '21 12:10 ps173

Well, this just cost me an entire day of debugging. 🤦‍♂️

For me, the problem was simply malformed CLI arguments combined with missing validation and poor error-reporting.

Might I propose, as an interim fix, we simply make the CLI print out it's configuration options before starting?

That way, we can at least tell if it's trying to do what we're trying to ask for.

My head hurts.

mindplay-dk avatar Jan 18 '22 14:01 mindplay-dk

I am able to trigger this error message using relative references that quicktype is unable to look up:

Schema 1 with "$id":"myschema/definitions/base" Schema 2 with "$id":"myschema/objects/foo" and using "$ref":"../definitions/base"

If I understand the spec correctly, the $id should set the base URL of the schema, allowing for $ref to be relative. Not sure if quicktype does not follow the ".." part of the URL correctly, or if it is invalid, but the error message is triggered, and in this context, sensible. It should however provide the line number.

relet avatar Nov 07 '23 13:11 relet