Callback for ext scripts always result in channel fault

With the latest genieacs-ext code, no extension can return successfully.

Every callback is converted into a fault, even if you correctly use callback(null, result).

The function would need to look like this:

function errorToFault(err: unknown): Fault | null {
  if (!err) return null;

  if (!(err instanceof Error) || !err.name)
    return { code: "ext", message: `${err}` };

  const fault: Fault = {
    code: `ext.${err.name}`,
    message: err.message,
    detail: {
      name: err.name,
      message: err.message,
    },
  };

  if (err.stack) {
    const detail = fault.detail as { stack?: string };
    detail.stack = err.stack;
    const stackTrimIndex = detail.stack.match(
      /\s+at\s[^\s]+\s\(.*genieacs-ext:.+\)/,
    );
    if (stackTrimIndex) {
      detail.stack = detail.stack.slice(0, stackTrimIndex.index);
    }
  }

  return fault;
}

I’m successfully using the following patch:

--- a/bin/genieacs-ext.ts
+++ b/bin/genieacs-ext.ts
@@ -8,7 +8,9 @@ let script: Record<
(args: unknown[ ], cb: (err: Error | null, res: unknown) => void) => void

> ;

-function errorToFault(err: unknown): Fault {
+function errorToFault(err: unknown): Fault | null {

* if (!err) return null;
* if (!(err instanceof Error) || !err.name)
  return { code: "ext", message: `${err}` };