nelak2 / nwscript-sinfar-language-server

NWScript Language Server modified to work for Sinfar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All async functions should be wrapped in try/catch blocks

Arthurmtro opened this issue · comments

ex:

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

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

public async getGlobalComplexTokensWithRef(computedChildren: string[] = []): Promise<OwnedComplexTokens[]> {
const localStandardLibDefinitions = this.collection.getLocalOnly("nwscript");
const tokens = await Promise.all(
this.children.flatMap(async (child) => {
// Cycling children or/and duplicates
if (computedChildren.includes(child)) {
return [];
} else {
computedChildren.push(child);
}
const childDocument = await this.collection.get(child);
if (!childDocument) {
return [];
}
return await childDocument.getGlobalComplexTokensWithRef(computedChildren);
}),
);
return [
{ owner: this.uri, tokens: this.complexTokens },
...(localStandardLibDefinitions
? [{ owner: localStandardLibDefinitions.uri, tokens: localStandardLibDefinitions.complexTokens }]
: []),
].concat(tokens.flat());
}

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?

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