Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNBT Improved Error Parsing Messages #39

Open
Offroaders123 opened this issue Nov 7, 2023 · 1 comment
Open

SNBT Improved Error Parsing Messages #39

Offroaders123 opened this issue Nov 7, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Offroaders123
Copy link
Owner

A reference to the discussion from Offroaders123/Dovetail#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 Offroaders123 added the enhancement New feature or request label Nov 7, 2023
@Offroaders123 Offroaders123 self-assigned this Nov 7, 2023
Offroaders123 added a commit that referenced this issue Nov 7, 2023
This is the real implementation for this. It actually didn't take too much to get it working!

I'm not sure whether the SNBT parsing implementation should make it mandatory for Float and Double tags to have a decimal spot. Currently you don't need to have one for it to parse correctly. This change here now just ensures that the output SNBT will now always have decimal places for simple Float and Double values.

#36
#38
#39
Offroaders123/Dovetail#5

https://stackoverflow.com/questions/175739/how-can-i-check-if-a-string-is-a-valid-number
https://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places (I thought it was going to be this one, but turns out it rounds the value, and forces the value to be within that length, unlike how I thought it was additive.)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
https://stackoverflow.com/questions/9838809/check-if-number-string-contains-decimal (I was going to use this next also, but then I realized that `Number.isInteger()` also covers the same thing, but with one less primitive type conversion, and a variable reference)

https://www.youtube.com/watch?v=z1j3RI3ZpsQ (asmr :), sleepy programming made this commit message take longer to write than normal, was dozing off a little bit; man this time change is still hard, gaining an hour is hard too because when you want to go to bed/wake up, it's not time yet, so you have to wait another hour to get to your normal time)
Offroaders123 added a commit that referenced this issue Nov 7, 2023
This actually worked out really well! Maybe I don't need to take the functional approach to organize things, the parameters still work great here too. I'm still up to trying to figure out that other approach though.

To make the error show up in the test runner, you can make `listItemAssertion ` set to `false`, and it will show the error for trying to parse the broken file associated with that check.
I'm still not totally sold on what to call the key for the RootTag, in the event that the root tag is indeed a ListTag.

I still need to add this check, as well as these improved errors, to `#readArray()`, where each list item type can be validated as the correct type or not.

#39

My eyes are getting so heavy/sleepy now, nearly done with these for the night.
@Offroaders123
Copy link
Owner Author

Further started to address implementing this enhancement in the commit above!

The naming of tag types here makes me want to migrate to an enum for the TAG constant mapping. That would make name appearance much easier, as well as just nicer here, plain out of the box. I don't like having to deal with the type-magic that comes with enums though. So, once again, we'll see. (Sleepy-self still talking here, I mean like using things such as List, ListTag, or TAG.LIST/LIST instead of the TAG number IDs themselves. I don't think the numerical IDs are very explanatory to the user, because they are just numbers. I know what each of the IDs are, but the error has to be debuggable by non-NBT fanatics like moi)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant