While writing some tests, the cleanup code always runs await app.stop(). However if the app wasn't started, trying to stop the app throws the following error message.
TypeError: Cannot read property 'close' of undefined
at Promise (/Users/taranveer/loopback/loopback-next/random/node_modules/@loopback/rest/dist/src/rest-server.js:417:20)
at new Promise (<anonymous>)
at RestServer.stop (/Users/taranveer/loopback/loopback-next/random/node_modules/@loopback/rest/dist/src/rest-server.js:416:16)
at _forEachServer.s (/Users/taranveer/loopback/loopback-next/random/node_modules/@loopback/core/dist/src/application.js:134:42)
at Promise.all.bindings.map (/Users/taranveer/loopback/loopback-next/random/node_modules/@loopback/core/dist/src/application.js:148:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Is this expected behaviour? Should stop catch error messages which indicate the server was never running and hence the app was successfully stopped?
Create app using lb4 app.
Create a new instance const app = new Application() ... now run app.stop() before starting it.
Is this the designed behaviour? I think it might be more intuitive to not thrown an error if a server is already stopped. Stop should throw a error is it wasn't able to stop a server.
@loopback/rest/src/rest-server.ts has a stop method -- It shouldn't throw an error if a server can't be stopped if it was never started! -- Other error's should still be propagated.Discussed with @raymondfeng , the user experience can be improved here. Marking it as bug.
@virkt25 , we've identified this as DP3. Could you please add the acceptance criteria? Thanks.
Done.
I think this can be tagged with good first issue. Does anyone else agree?
Most helpful comment
I think this can be tagged with
good first issue. Does anyone else agree?