NBTify icon indicating copy to clipboard operation
NBTify copied to clipboard

SNBT Improved Error Parsing Messages

Open Offroaders123 opened this issue 8 months ago • 1 comments

A reference to the discussion from https://github.com/Offroaders123/Dovetail/issues/5:

I also think I need to look into improving the error messages with as to what part of the SNBT content isn't valid/parsing correctly. Say for this error, I could add a reference that it's in the array at key InvalidBecauseTheValuesArentOfTheSameType at item index [2], where that item is of type ShortTag, but the ListTag here can only accept ByteTag values. Something along the lines of that.

Current SNBT Parsing Error Message

I think I can better accomplish this kind of handling if I bring the SNBT parser implementation back to a fully functional approach, rather than managing it with a class kind of thing. I can use callbacks of some sort which could allow the use of parameters that have the current key name and value or something like that, same with the current array index, item type, and other similar metadata-related things. It's like how you can use [].map((item,index,array) => {}) to get information about the iteration, as well as the source data you're working with, right from the callback.

Maybe I can look again into a more functional approach for the rest of the NBT reading and writing too, it doesn't have to be exclusively for SNBT handling. I do think the use of a class to manage the internal ArrayBuffer and DataView references is a little simpler to understand than passing them around everywhere too though. So, we'll see about that one. I feel SNBT's work with string manipulation and appending is a bit more akin to simple return types though, hence why it works naturally with a functional approach. It's not as straightforward to do that for the NBT parsing/writing counterparts.

Offroaders123 avatar Nov 07 '23 08:11 Offroaders123