nelak2 / nwscript-sinfar-language-server

NWScript Language Server modified to work for Sinfar
MIT License
2 stars 0 forks source link

All async functions should be wrapped in try/catch blocks #6

Open Arthurmtro opened 1 year ago

Arthurmtro commented 1 year ago

ex:

const test =  async () => {
   try {
      const res = await Promise.resolve(...)

    throw(...error...)
   } catch (e)  {
      ...
   }
}

https://github.com/nelak2/nwscript-sinfar-language-server/blob/c5afa5430fef7296ccdbac865df96269efc1e7b9/server/src/Documents/Document.ts#L43-L70

nelak2 commented 1 year ago

This will probably require a pretty significant reworking of the code since async functions require their calling functions to also be async which causes almost every function to end up being async (Except the top-level functions). I definitely understand the value of it though because a lot of the issues I run into is async functions failing. They don't seem to throw exceptions normally from what I've seen. Instead, the code just fails silently. Will that cause those exceptions to be caught reliably?

Arthurmtro commented 1 year ago

Yeah using catch will get rid of the crashs as you will handle them. Plus you will understand better how to clean your code base