mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	[image] Catch and report svg load errors (#11619)
This commit is contained in:
		@@ -671,18 +671,33 @@ async def write_image(config, all_frames=False):
 | 
				
			|||||||
    resize = config.get(CONF_RESIZE)
 | 
					    resize = config.get(CONF_RESIZE)
 | 
				
			||||||
    if is_svg_file(path):
 | 
					    if is_svg_file(path):
 | 
				
			||||||
        # Local import so use of non-SVG files needn't require cairosvg installed
 | 
					        # Local import so use of non-SVG files needn't require cairosvg installed
 | 
				
			||||||
 | 
					        from pyexpat import ExpatError
 | 
				
			||||||
 | 
					        from xml.etree.ElementTree import ParseError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        from cairosvg import svg2png
 | 
					        from cairosvg import svg2png
 | 
				
			||||||
 | 
					        from cairosvg.helpers import PointError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not resize:
 | 
					        if not resize:
 | 
				
			||||||
            resize = (None, None)
 | 
					            resize = (None, None)
 | 
				
			||||||
        with open(path, "rb") as file:
 | 
					        try:
 | 
				
			||||||
            image = svg2png(
 | 
					            with open(path, "rb") as file:
 | 
				
			||||||
                file_obj=file,
 | 
					                image = svg2png(
 | 
				
			||||||
                output_width=resize[0],
 | 
					                    file_obj=file,
 | 
				
			||||||
                output_height=resize[1],
 | 
					                    output_width=resize[0],
 | 
				
			||||||
            )
 | 
					                    output_height=resize[1],
 | 
				
			||||||
        image = Image.open(io.BytesIO(image))
 | 
					                )
 | 
				
			||||||
        width, height = image.size
 | 
					            image = Image.open(io.BytesIO(image))
 | 
				
			||||||
 | 
					            width, height = image.size
 | 
				
			||||||
 | 
					        except (
 | 
				
			||||||
 | 
					            ValueError,
 | 
				
			||||||
 | 
					            ParseError,
 | 
				
			||||||
 | 
					            IndexError,
 | 
				
			||||||
 | 
					            ExpatError,
 | 
				
			||||||
 | 
					            AttributeError,
 | 
				
			||||||
 | 
					            TypeError,
 | 
				
			||||||
 | 
					            PointError,
 | 
				
			||||||
 | 
					        ) as e:
 | 
				
			||||||
 | 
					            raise core.EsphomeError(f"Could not load SVG image {path}: {e}") from e
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        image = Image.open(path)
 | 
					        image = Image.open(path)
 | 
				
			||||||
        width, height = image.size
 | 
					        width, height = image.size
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user