mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	server,electron: Improve error logging
This commit is contained in:
		
							parent
							
								
									c6d043b42c
								
							
						
					
					
						commit
						40651e9852
					
				
							
								
								
									
										27
									
								
								src/www.ts
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/www.ts
									
									
									
									
									
								
							@ -126,6 +126,8 @@ function startHttpServer() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    httpServer.on('error', error => {
 | 
			
		||||
        let message = error.message;
 | 
			
		||||
 | 
			
		||||
        if (!listenOnTcp || ("syscall" in error && error.syscall !== 'listen')) {
 | 
			
		||||
            throw error;
 | 
			
		||||
        }
 | 
			
		||||
@ -134,17 +136,28 @@ function startHttpServer() {
 | 
			
		||||
        if ("code" in error) {
 | 
			
		||||
            switch (error.code) {
 | 
			
		||||
                case 'EACCES':
 | 
			
		||||
                    console.error(`Port ${port} requires elevated privileges. It's recommended to use port above 1024.`);
 | 
			
		||||
                    process.exit(1);
 | 
			
		||||
                    message = `Port ${port} requires elevated privileges. It's recommended to use port above 1024.`;
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'EADDRINUSE':
 | 
			
		||||
                    console.error(`Port ${port} is already in use. Most likely, another Trilium process is already running. You might try to find it, kill it, and try again.`);
 | 
			
		||||
                    process.exit(1);
 | 
			
		||||
                    message = `Port ${port} is already in use. Most likely, another Trilium process is already running. You might try to find it, kill it, and try again.`;
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw error;
 | 
			
		||||
    }
 | 
			
		||||
    )
 | 
			
		||||
        if (!message) {
 | 
			
		||||
            message = "An unexpected error has occurred.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (utils.isElectron()) {
 | 
			
		||||
            import("electron").then(({ dialog }) => {
 | 
			
		||||
                dialog.showErrorBox("Error while initializing the server", message);
 | 
			
		||||
                process.exit(1);
 | 
			
		||||
            });
 | 
			
		||||
        } else {
 | 
			
		||||
            console.error(message);
 | 
			
		||||
            process.exit(1);
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    httpServer.on('listening', () => {
 | 
			
		||||
        if (listenOnTcp) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user