mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 06:33:51 +00:00 
			
		
		
		
	[font] Catch file load exception (#10058)
Co-authored-by: clydeps <U5yx99dok9>
This commit is contained in:
		
				
					committed by
					
						 Jesse Hills
						Jesse Hills
					
				
			
			
				
	
			
			
			
						parent
						
							a9b27d1966
						
					
				
				
					commit
					da573a217d
				
			| @@ -15,6 +15,7 @@ from freetype import ( | ||||
|     FT_LOAD_RENDER, | ||||
|     FT_LOAD_TARGET_MONO, | ||||
|     Face, | ||||
|     FT_Exception, | ||||
|     ft_pixel_mode_mono, | ||||
| ) | ||||
| import requests | ||||
| @@ -94,7 +95,14 @@ class FontCache(MutableMapping): | ||||
|         return self.store[self._keytransform(item)] | ||||
|  | ||||
|     def __setitem__(self, key, value): | ||||
|         self.store[self._keytransform(key)] = Face(str(value)) | ||||
|         transformed = self._keytransform(key) | ||||
|         try: | ||||
|             self.store[transformed] = Face(str(value)) | ||||
|         except FT_Exception as exc: | ||||
|             file = transformed.split(":", 1) | ||||
|             raise cv.Invalid( | ||||
|                 f"{file[0].capitalize()} {file[1]} is not a valid font file" | ||||
|             ) from exc | ||||
|  | ||||
|  | ||||
| FONT_CACHE = FontCache() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user