ameliorate icon indicating copy to clipboard operation
ameliorate copied to clipboard

Show error if user uploads topic with invalid JSON

Open keyserj opened this issue 2 years ago • 0 comments

Describe the bug Users can upload any JSON file they want, and JSON that doesn't fit the diagram store's type will not work. Not a big deal since invalid JSON results in no change, but informing the user (and explicitly causing no change) would be good.

To Reproduce Steps to reproduce the behavior:

  1. Click upload button
  2. Select a JSON file that doesn't match the standard topic format
  3. Observe no message is displayed, and diagram does not change

Expected behavior Inform the user (probably dialog box) if a topic upload cannot be completed because the JSON is invalid.

Screenshots image

Additional context Add any other context about the problem here.

Technical ideas Code where uploading is done

With some brief investigation, it seems like there's no easy way to use typescript types at runtime for validation. zod is a very popular validation library that is probably good enough, but it seems not quite ideal - it essentially requires inferring typescript types from a zod schema, OR creating a zod schema that matches your typescript types. It also seems a little overkill because it enables validating specific requirements beyond types (e.g. number than is within X range, string that's 5+ characters long, etc).

Maybe we can just try setting the topic data, and if the data doesn't change, we assume it failed and show an error.

keyserj avatar Dec 27 '22 17:12 keyserj