question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error event from socket

See original GitHub issue

Hey guys, After update to 4.0.3 version, I’m randomly facing exceptions.

js script:

const TuyAPI = require('tuyapi');

const device = new TuyAPI({
  id: 'xxxx',
  key: 'xxxx',
  ip: '10.1.0.10'});

(async () => {

var argv = require('minimist')(process.argv.slice(2));
	var settings = {};
	if (argv['sound'] == 'true'){
		settings['132'] = true;
	} else if (argv['sound'] == 'false'){
		settings['132'] = false;
	}
	if (argv['start'] == 'true'){
		settings['127'] = true;
	} else if (argv['start'] == 'false'){
		settings['127'] = false;
	}
	if (argv['mist'] == '1'){
		settings['123'] = '1';
	} else if (argv['mist'] == '2'){
		settings['123'] = '2';
	}
	if (argv['light'] == 'true'){
		settings['133'] = '00f6fc00b56464';
		settings['131'] = 3456;
		settings['125'] = true;
	} else if (argv['light'] == 'false'){
		settings['125'] = false;
	}
	if (argv['warning'] == 'true'){
		settings['133'] = 'fc0c0000036464';
		settings['125'] = true;
	}

	await device.find();

	await device.connect();
	if (argv['check'] == 'true') {
		status = await device.get({dps: 127});
		console.log('Current status:', status);
	} else if (argv['status'] == 'true') {
		let data = await device.get({schema: true});
		console.log('Data from device:', data);
	} else {
		await device.set({
			  multiple: true,
			  data: settings});
		console.log('device was changed');
		console.dir(settings);
	};
	device.disconnect();
})();

Exception:

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: Error from socket
    at Socket.client.on.err (/home/openhabian/node_modules/tuyapi/index.js:391:30)
    at Socket.emit (events.js:189:13)
    at onwriteError (_stream_writable.js:431:12)
    at onwrite (_stream_writable.js:456:5)
    at _destroy (internal/streams/destroy.js:40:7)
    at Socket._destroy (net.js:607:3)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at WriteWrap.afterWrite [as oncomplete] (net.js:784:10)
Emitted 'error' event at:
    at Socket.client.on.err (/home/openhabian/node_modules/tuyapi/index.js:391:16)
    at Socket.emit (events.js:189:13)
    [... lines matching original stack trace ...]
    at WriteWrap.afterWrite [as oncomplete] (net.js:784:10)

Debug Output:

  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 10.1.0.10... +7ms
  TuyAPI Socket connected. +14ms
  TuyAPI GET Payload: +2ms
  TuyAPI { gwId: 'XXX', devId: 'XXX' } +1ms
  TuyAPI Error event from socket. 10.1.0.10 { Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:782:14) errno: 'EPIPE', code: 'EPIPE', syscall: 'write' } +24ms
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: Error from socket
    at Socket.client.on.err (/home/openhabian/node_modules/tuyapi/index.js:391:30)
    at Socket.emit (events.js:189:13)
    at onwriteError (_stream_writable.js:431:12)
    at onwrite (_stream_writable.js:456:5)
    at _destroy (internal/streams/destroy.js:40:7)
    at Socket._destroy (net.js:607:3)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at WriteWrap.afterWrite [as oncomplete] (net.js:784:10)
Emitted 'error' event at:
    at Socket.client.on.err (/home/openhabian/node_modules/tuyapi/index.js:391:16)
    at Socket.emit (events.js:189:13)
    [... lines matching original stack trace ...]
    at WriteWrap.afterWrite [as oncomplete] (net.js:784:10)

Desktop:

  • raspberian
  • Node 10.15.1

Any idea what’s wrong there? For me, repro is random. I didn’t find proper repro steps. I’m starting same script with exact same parameters and in most cases it works, but sometimes it throw this exception. Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
codethewebcommented, Feb 25, 2019

@ramon18 may be right, in my (limited) testing it appears the .get() in .connect() may be the root cause of errors like this one. I’ll do further testing, but I may end up removing the initial get.

1reaction
codethewebcommented, Aug 16, 2019

@ls819011 have you tried with v5.1.2? It contains some bug fixes that may resolve the issues you’re seeing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Socket.IO - Error Handling - Tutorialspoint
Error − An error event is sent from the server. Message − When the server sends a message using the send function. Reconnect...
Read more >
How to catch socket.io errors and prevent them from showing ...
The only way to hide that error is by never calling io.connect in the first place – which of course would mean your...
Read more >
Listening to events | Socket.IO
There is currently no built-in error handling in the Socket.IO library, which means you must catch any error that could be thrown in...
Read more >
Unhandled 'error' event when connect followed by close #1835
If this happens immediately after the instantiation of the Websocket client, the following error happens: node:events:353 throw er; ...
Read more >
Handling event responses and failures - SocketCluster
Here is how to handle various responses and errors (sample code): ... Client code socket.emit('ping', 'This is a ping', function (err, responseData) {...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found