How does one handle an incorrect resource file?

I’m starting the parser that will handle one of the key features of my app and realizing exactly who easy it would be for me to screw up a resource file that is provided to the application. For example, a simple resource that I provide to my app is a JSON file that contains an entity layout (name, fascia, location etc…). It would be easy for me to leave out the name of the entity or misspell the JSON key.

Obviously catastrophic failures during parsing are to be handled in a try/catch, but how would subtle failures (such as a dyslexic spelling of name) be handled?

What’s the difference between a “catastrophic failure during parsing” and a “dyslexic fail” (say a , instead of a ;, or a ' instead of a " – those two pairs of symbols are on neighboring keys on my keyboard), fundamentally, from the end-user’s* point of view?

If the JSON** is malformed due to a typo, giving a good error message is usually not trivial because from the parser‘s point of view, the (catastrophic) error might not be where the actual error is from a human point of view. So, in my opinion, the case you’re “dismissing” as a technical detail is the hard one to deal with.

If you have a valid JSON file, but missing (or extraneous) properties, giving a good error message (i.e. failing the right way) is comparatively trivial: just tell the user what you’re expecting that’s not there, or doesn’t have the right kind of value. You can make that even easier to the user if you state in the error message things like “keys are case-sensitive” or “dates must be entered in dd/mm/yyyy format” or whatever is relevant.

How you technically implement that will depend on the language, but keeping a list of mandatory and optional parameters (with their value types and default values) is not technically challenging – you could, in fact, do that with a JSON file that would be used both as input to your parser and as a source for your docs.
Build and maintain that list, and you’re done. Have a few testcase resources and make sure your parser (and “constructors”) fails hard (at least during automated tests) when a mandatory property is missing, or yields a big warning if an unknown property is present (not in that list).
If you add mandatory properties to your code, but forget to update that list, your testcases will tell you – either by the parser detecting that, or the “constructors” yelling at you because they’re missing data. Same thing if you change names or value types.

*You phrased your question in such a way that you seem to be the end-user. But if that resource loading is a key feature of your app, keep in mind that there will hopefully be many more people playing with that.
**Substitue any format here.

How would subtle failures (such as a dyslexic spelling of name) be
handled?

Unit testing. I don’t know what language you are using, but JUnit works great in Java and Scala. You are writing something that takes in some kind of input and produces JSON? Start by making a test that feeds it a known good input file and checks to see that the output is exactly what you want. Once you have a few tests written, you can change your code and have run the test to have a sense that the basic functionality that was there before is still working.

Another possible solution is to make your application that reads the JSON really good at reporting errors, deciding when to reject input vs. continue processing after an error is encountered (fatal and non-fatal errors), and correcting for small common mistakes.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật