File tree Expand file tree Collapse file tree 3 files changed +54
-6
lines changed
packages/neovim/src/utils Expand file tree Collapse file tree 3 files changed +54
-6
lines changed Original file line number Diff line number Diff line change 8
8
makes it more useful for GUIs where ` $PATH ` is often different than the user's
9
9
shell. #267
10
10
- ` findNvim ` supports optional ` paths ` and ` dirs ` parameters.
11
+ - Invalid RPC error now shows the contents of the invalid RPC message. #404
11
12
12
13
## [ 5.2.1] ( https://github.com/neovim/node-client/compare/v5.2.0...v5.2.1 )
13
14
Original file line number Diff line number Diff line change
1
+ /* eslint-env jest */
2
+ import { EventEmitter } from 'node:events' ;
3
+ import { Readable , Writable } from 'node:stream' ;
4
+ import * as msgpack from '@msgpack/msgpack' ;
5
+ import { attach } from '../attach/attach' ;
6
+ import { exportsForTesting } from './transport' ;
7
+
8
+ describe ( 'transport' , ( ) => {
9
+ it ( 'throws on invalid RPC message' , done => {
10
+ const invalidPayload = { bogus : 'nonsense' } ;
11
+ const onTransportFail : EventEmitter = exportsForTesting . onTransportFail ;
12
+ onTransportFail . on ( 'fail' , ( errMsg : string ) => {
13
+ expect ( errMsg ) . toEqual (
14
+ "invalid msgpack-RPC message: expected array, got: { bogus: 'nonsense' }"
15
+ ) ;
16
+ done ( ) ;
17
+ } ) ;
18
+
19
+ // Create fake reader/writer and send a (broken) message.
20
+ const fakeReader = new Readable ( { read ( ) { } } ) ;
21
+ const fakeWriter = new Writable ( { write ( ) { } } ) ;
22
+
23
+ const nvim = attach ( { reader : fakeReader , writer : fakeWriter } ) ;
24
+ void nvim ; // eslint-disable-line no-void
25
+
26
+ // Simulate an invalid message on the channel.
27
+ const msg = msgpack . encode ( invalidPayload ) ;
28
+ fakeReader . push ( Buffer . from ( msg . buffer , msg . byteOffset , msg . byteLength ) ) ;
29
+ } ) ;
30
+ } ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ import {
13
13
} from '@msgpack/msgpack' ;
14
14
import { Metadata } from '../api/types' ;
15
15
16
+ export let exportsForTesting : any ; // eslint-disable-line import/no-mutable-exports
17
+ // jest sets NODE_ENV=test.
18
+ if ( process . env . NODE_ENV === 'test' ) {
19
+ exportsForTesting = {
20
+ onTransportFail : new EventEmitter ( ) ,
21
+ } ;
22
+ }
23
+
16
24
class Response {
17
25
private requestId : number ;
18
26
@@ -122,16 +130,25 @@ class Transport extends EventEmitter {
122
130
breakLength : 500 ,
123
131
} ) ;
124
132
} catch ( error ) {
125
- console . error ( 'Failed to inspect value: ' , error ) ;
133
+ // Do nothing.
126
134
}
127
- throw new TypeError (
128
- `Expected msgpack result to be an array, but got ${ valstr } `
129
- ) ;
135
+
136
+ const errMsg = `invalid msgpack-RPC message: expected array, got: ${ valstr } ` ;
137
+ const onFail : EventEmitter = exportsForTesting ?. onTransportFail ;
138
+ if ( onFail ) {
139
+ // HACK: for testing only.
140
+ // TODO(justinmk): let the tests explicitly drive the messages.
141
+ onFail . emit ( 'fail' , errMsg ) ;
142
+ return ;
143
+ }
144
+ throw new TypeError ( errMsg ) ;
130
145
}
146
+
131
147
this . parseMessage ( resolved . value ) ;
132
- return resolveGeneratorRecursively ( iter ) ;
148
+ resolveGeneratorRecursively ( iter ) ;
149
+ return ;
133
150
}
134
- return Promise . resolve ( ) ;
151
+ Promise . resolve ( ) ;
135
152
} ) ;
136
153
} ;
137
154
You can’t perform that action at this time.
0 commit comments