stevearc / godot_parser

Python library for parsing Godot scene files
MIT License
55 stars 11 forks source link

Binary parent scenes cause exception #6

Closed tom-leys closed 3 years ago

tom-leys commented 3 years ago

This one is pretty obvious, but perhaps something to wrap in a friendly "I can't do that Dave" style exception.

I have a .tscn file (text-based) which inherits from a .scn file (binary).

When I open the .tscn file in tree mode, I get an exception.

I suggest that until you start supporting .scn files you catch and re-raise this exception as something akin to "Binary files are not supported yet"

Thanks

c:\users\tom\appdata\local\programs\python\python39\lib\site-packages\godot_parser\tree.py in _load_parent_scene(root, file)
    327 
    328 def _load_parent_scene(root: Node, file: GDFile):
--> 329     parent_file: GDFile = file.load_parent_scene()
    330     parent_tree = Tree.build(parent_file)
    331     # Transfer parent scene's children to this scene

c:\users\tom\appdata\local\programs\python\python39\lib\site-packages\godot_parser\files.py in load_parent_scene(self)
    256                 "Could not find parent scene resource id(%d)" % root.instance
    257             )
--> 258         return GDScene.load(gdpath_to_filepath(self.project_root, parent_res.path))
    259 
    260     @contextmanager

c:\users\tom\appdata\local\programs\python\python39\lib\site-packages\godot_parser\files.py in load(cls, filepath)
    306     def load(cls: Type[GDFileType], filepath: str) -> GDFileType:
    307         with open(filepath, "r") as ifile:
--> 308             file = cls.parse(ifile.read())
    309         file.project_root = find_project_root(filepath)
    310         return file

c:\users\tom\appdata\local\programs\python\python39\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1848: character maps to <undefined>
stevearc commented 3 years ago

Added better error message. Thanks for the report!