Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous Errors not Handled Properly #112

Open
Omaro-IB opened this issue Nov 6, 2024 · 0 comments
Open

Asynchronous Errors not Handled Properly #112

Omaro-IB opened this issue Nov 6, 2024 · 0 comments
Labels

Comments

@Omaro-IB
Copy link

Omaro-IB commented Nov 6, 2024

Bug Description

When certain functions (I encountered the error with mpv.getProperty but I assume it also occurs with other async functions) are called before mpv.start(), node crashes instead of throwing an error or something

How To Reproduce

Steps to reproduce the behavior: just call mpv.getProperty("filename") without mpv.start() first

Expected behavior

Some error is printed to the console without crashing the program

Software Versions
  • Node-Mpv: 2.0.0-beta.2
  • MPV: mpv 0.37.0
  • OS: Linux Debian (Kubuntu)
Additional context

The Socket class in the node:net module provides event listeners which can be used to handle these errors. For example, for the send function:

send: function(command) {
		return new Promise((resolve, reject) => {

			...

			// create an ipcRequest object to store the required information for error messages
			// put the resolve function in the ipcRequests dictionary to call it later
			this.ipcRequests[request_id] = new ipcRequest(resolve, reject, Object.values(command).splice(1));

			// BEGIN: patch
			// Listen for the "error" event
			const handleError = (err) => {this.socket.removeListener('error', handleError); return reject('An error occurred:', err.message)}  // TODO: improve error message
			this.socket.on('error', handleError);
			// END: patch

			try{
				this.socket.write(JSON.stringify(messageJson) + '\n');
			}
			// reject the promise in case of an error
			catch(error) {
				return reject(this.errorHandler.errorMessage(7, message, 'send()', JSON.stringify(command)));
			}
		})

	}
@Omaro-IB Omaro-IB added the bug label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant