node-modbus icon indicating copy to clipboard operation
node-modbus copied to clipboard

Error messages should contain an request object (like in await readHoldingRegisters(..))

Open vogsphar opened this issue 6 years ago • 6 comments

On success (normal resp) i am not interested in the request, but when errors occur it would be good to know what was send to the Server.

vogsphar avatar Feb 12 '20 09:02 vogsphar

Can you give an example to describe what you are talking about?

alexbuczynsky avatar Feb 13 '20 02:02 alexbuczynsky

A successfull response contains {metrics,request,response} The UserRequestError Object only contains {err,message,response} It would be helpfull to also add request (and metrics?) to UserRequestError {err,message,request,response}.

UserRequestError {
  err: 'ModbusException',
  message: 'A Modbus Exception Occurred - See Response Body',
  response: ModbusTCPResponse {
    _id: 2,
    _protocol: 0,
    _bodyLength: 3,
    _unitId: 24,
    _body: ExceptionResponseBody { _fc: 3, _code: 2 }
  }
}
{
  metrics: UserRequestMetrics {
    createdAt: 2020-02-21T07:56:33.867Z,
    startedAt: 2020-02-21T07:56:33.867Z,
    receivedAt: 2020-02-21T07:56:33.872Z
  },
  request: ModbusTCPRequest {
    _id: 1,
    _protocol: 0,
    _length: 6,
    _unitId: 24,
    _body: ReadHoldingRegistersRequestBody { _fc: 3, _start: 0, _count: 2 }
  },
  response: ModbusTCPResponse {
    _id: 1,
    _protocol: 0,
    _bodyLength: 7,
    _unitId: 24,
    _body: ReadHoldingRegistersResponseBody {
      _fc: 3,
      _byteCount: 4,
      _values: [Array],
      _bufferLength: 6,
      _valuesAsArray: [Array],
      _valuesAsBuffer: <Buffer 43 c8 01 48>
    }
  }
}

vogsphar avatar Feb 21 '20 08:02 vogsphar

A successfull response contains {metrics,request,response}

Where is this happening?

stefanpoeter avatar Mar 31 '20 10:03 stefanpoeter

@stefanpoeter that is in v4.0

Here is an example: https://github.com/Cloud-Automation/node-modbus/blob/88bf1c20c75740b10e9adea8e6dcdc70795604a7/examples/typescript/tcp/ReadHoldingRegisters.ts#L16-L21

alexbuczynsky avatar Mar 31 '20 15:03 alexbuczynsky

Ah, I never noticed :-) Well @vogsphar is right, it totally makes sense that this is in the error response as well. I don't think it would corrupt the API. I'll put it on this weeks todo list.

stefanpoeter avatar Mar 31 '20 16:03 stefanpoeter

Sounds good. Adding it should be fine. I can tackle adding it to the 4.0 version.

alexbuczynsky avatar Mar 31 '20 16:03 alexbuczynsky