improve error handling
Make sure all errors are able to return their traces to be displayed, and that only the code appears in the pop-up, not a mix with the actual content.
This commit is contained in:
		
							parent
							
								
									76bf6cefaa
								
							
						
					
					
						commit
						e152034eeb
					
				
					 3 changed files with 81 additions and 79 deletions
				
			
		|  | @ -52,15 +52,15 @@ export default class alerts { | |||
| 	@param {number} ERROR_MESSAGE the custom error message | ||||
| 	@param {boolean} critical the critical nature | ||||
| 	*/ | ||||
| 	static error(ERROR_CODE, ERROR_MESSAGE, critical = true) { | ||||
| 	static error(ERROR_CODE, ERROR_MESSAGE, ERROR_STACK, critical = true) { | ||||
| 		(async () => { | ||||
| 			// Import the templating.
 | ||||
| 			const texts = (await import(chrome.runtime.getURL("gui/scripts/read.js"))).default; | ||||
| 
 | ||||
| 			// Display the error message.
 | ||||
| 			console.error(texts.localized(`error_msg`, null, [ERROR_CODE, ERROR_MESSAGE])); | ||||
| 			console.error(texts.localized(`error_msg`, false, [ERROR_CODE, ERROR_MESSAGE, ERROR_STACK])); | ||||
| 			if (critical) { | ||||
| 				alert(texts.localized(`error_msg_GUI`, null, [String(ERROR_CODE)])); | ||||
| 				alert(texts.localized(`error_msg_GUI`, false, [String(ERROR_CODE)])); | ||||
| 			} else { | ||||
| 				try { | ||||
| 					M.toast({ text: message }); | ||||
|  |  | |||
|  | @ -22,20 +22,20 @@ export default class windowman { | |||
| 		let LOAD_STATE = true; | ||||
| 		let UI = { | ||||
| 			CSS: [ | ||||
|           chrome.runtime.getURL( | ||||
|             "gui/styles/external/fonts/materialdesignicons.min.css", | ||||
|           ), | ||||
|           chrome.runtime.getURL( | ||||
|             "gui/styles/external/materialize/css/materialize.css", | ||||
|           ), | ||||
| 				chrome.runtime.getURL("gui/styles/external/fonts/materialdesignicons.min.css"), | ||||
| 				chrome.runtime.getURL("gui/styles/external/materialize/css/materialize.css"), | ||||
| 				chrome.runtime.getURL("gui/styles/ui.css"), | ||||
|         ], | ||||
| 			] | ||||
| 		}; | ||||
| 
 | ||||
| 		for (let index = 0; index < UI[`CSS`].length; index++) { | ||||
| 			const source = UI.CSS[index]; | ||||
| 
 | ||||
| 			try { | ||||
| 				(async () => { | ||||
| 					// Import source reading for later. 
 | ||||
| 					const reader = (await import(chrome.runtime.getURL(`/gui/scripts/read.js`))).default; | ||||
| 					 | ||||
| 					const net = await import(chrome.runtime.getURL(`/scripts/net.js`)); | ||||
| 
 | ||||
| 					let resource = false; | ||||
|  | @ -50,23 +50,26 @@ export default class windowman { | |||
| 						metadata_element.setAttribute(`href`, source); | ||||
| 						document.querySelector(`head`).appendChild(metadata_element); | ||||
| 					} else { | ||||
|             const alerts = ( | ||||
|               await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`)) | ||||
|             ).default; | ||||
|             const reader = ( | ||||
|               await import(chrome.runtime.getURL(`/gui/scripts/read.js`)) | ||||
|             ).default; | ||||
| 						throw new ReferenceError(reader.localized(`error_msg_fileNotFound`)); | ||||
| 					} | ||||
| 					 | ||||
|             alerts.error(-1, reader.localized(`error_msg_fileNotFound`), true, [ | ||||
|               source, | ||||
|             ]); | ||||
| 				})(); | ||||
| 			} catch(err) { | ||||
| 				(async() => { | ||||
| 					const alerts = (await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))).default; | ||||
| 					 | ||||
| 					// Raise an alert. 
 | ||||
| 					alerts.error(err.name, err.message, err.stack, true, [source]); | ||||
| 
 | ||||
| 					// Stop loading the page when an error has occured; it's not going to work!
 | ||||
| 					if (!DEBUG) { | ||||
| 						window.close(); | ||||
| 					} | ||||
|           } | ||||
| 				})(); | ||||
| 				 | ||||
| 				// Stop loading immediately during the error. 
 | ||||
| 				break; | ||||
| 			}; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  | @ -453,11 +456,6 @@ export default class windowman { | |||
|             input_elements.forEach((input_element) => { | ||||
|               if (input_element.getAttribute("data-enable")) { | ||||
|                 (async () => { | ||||
|                   console.log( | ||||
|                     await secretariat.read( | ||||
|                       input_element.getAttribute("data-enable"), | ||||
|                     ), | ||||
|                   ); | ||||
|                   input_element.disabled = !((await secretariat.read( | ||||
|                     input_element.getAttribute("data-enable"), | ||||
|                   )) != null | ||||
|  |  | |||
|  | @ -20,19 +20,23 @@ export async function download(URL, type, verify_only = false) { | |||
| 		data; | ||||
| 
 | ||||
| 	if (connect.ok && !verify_only) { | ||||
| 		try { | ||||
| 			data = await connect.text(); | ||||
| 		 | ||||
|     try { | ||||
|     } catch (err) { | ||||
| 			if ( | ||||
| 				type | ||||
|           ? type.toLowerCase().includes(`json`) || | ||||
|             type.toLowerCase().includes(`dictionary`) | ||||
| 					? type.toLowerCase().includes(`json`) || type.toLowerCase().includes(`dictionary`) | ||||
| 					: false | ||||
| 			) { | ||||
| 				try { | ||||
| 				data = JSON.parse(data); | ||||
|       } | ||||
|       alert.error(texts.localized(`error_msg_notJSON`, false)); | ||||
| 				// When not in JSON, run this.
 | ||||
| 				} catch(err) { | ||||
| 					throw new TypeError(texts.localized(`error_msg_notJSON`, false)); | ||||
| 				}; | ||||
| 			}; | ||||
| 		} catch(err) { | ||||
| 			alert.error(err.name, err.message, err.stack); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue