<p dir="auto">Found an error:</p>
<p dir="auto"><a href="https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=false&amp;code=%0Afunction%20safeAsync%28fn%29%20%7B%0A%20%20return%20async%20%28...args%29%20%3D%3E%20%7B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20await%20fn%28...args%29%0A%20%20%20%20%7D%20catch%20%28err%29%20%7B%0A%20%20%20%20%20%20handleError%28err%29%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%0Aasync%20function%20a%20%28q%29%20%7B%0A%20%20console.log%28q%29%0A%7D%0A%0Aasync%20function%20m%28%29%20%7B%0A%20%20await%20safeAsync%28a%29%28123%29%0A%7D%0A%0Am%28%29%0A" rel="nofollow">Example 1</a></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function safeAsync(fn) {
  return async (...args) =&gt; {
    try {
      await fn(...args)
    } catch (err) {
      handleError(err)
    }
  }
}

async function a(q) {
  console.log(q)
}

async function m() {
  await safeAsync(a)(123)
}

// should print 123, but prints [Function a]
m()"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">safeAsync</span><span class="pl-kos">(</span><span class="pl-s1">fn</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-k">async</span> <span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">try</span> <span class="pl-kos">{</span>
      <span class="pl-k">await</span> <span class="pl-s1">fn</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-en">handleError</span><span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">a</span><span class="pl-kos">(</span><span class="pl-s1">q</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">q</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">m</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">await</span> <span class="pl-en">safeAsync</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-c1">123</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-c">// should print 123, but prints [Function a]</span>
<span class="pl-en">m</span><span class="pl-kos">(</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">But if I add <code class="notranslate">console.log(args)</code>, it's working:</p>
<p dir="auto"><a href="https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=false&amp;code=%0Afunction%20safeAsync%28fn%29%20%7B%0A%20%20return%20async%20%28...args%29%20%3D%3E%20%7B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20console.log%28args%29%0A%20%20%20%20%20%20await%20fn%28...args%29%0A%20%20%20%20%7D%20catch%20%28err%29%20%7B%0A%20%20%20%20%20%20handleError%28err%29%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A%0Aasync%20function%20a%20%28q%29%20%7B%0A%20%20console.log%28q%29%0A%7D%0A%0Aasync%20function%20m%28%29%20%7B%0A%20%20await%20safeAsync%28a%29%28123%29%0A%7D%0A%0Am%28%29%0A" rel="nofollow">Example 2</a></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
function safeAsync(fn) {
  return async (...args) =&gt; {
    try {
      console.log(args)
      await fn(...args)
    } catch (err) {
      handleError(err)
    }
  }
}

async function a (q) {
  console.log(q)
}

async function m() {
  await safeAsync(a)(123)
}


// prints [123] 123 as expected
m()"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">safeAsync</span><span class="pl-kos">(</span><span class="pl-s1">fn</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-k">async</span> <span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">try</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">args</span><span class="pl-kos">)</span>
      <span class="pl-k">await</span> <span class="pl-s1">fn</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-en">handleError</span><span class="pl-kos">(</span><span class="pl-s1">err</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">a</span> <span class="pl-kos">(</span><span class="pl-s1">q</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">q</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">m</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">await</span> <span class="pl-en">safeAsync</span><span class="pl-kos">(</span><span class="pl-s1">a</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-c1">123</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>


<span class="pl-c">// prints [123] 123 as expected</span>
<span class="pl-en">m</span><span class="pl-kos">(</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">Hi,</p>
<p dir="auto">It seems there is a bug when combining async + rest parameters syntax.<br>
Here is a simplified version that reproduces the case with a simple async of value.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const foo = async (...msgs) =&gt; {
  let t = await msgs[0];
  console.log(t);
}

foo('a'); // displays &quot;{}&quot; instead of &quot;a&quot; value"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-en">foo</span> <span class="pl-c1">=</span> <span class="pl-k">async</span> <span class="pl-kos">(</span>...<span class="pl-s1">msgs</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">let</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">msgs</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">t</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s">'a'</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// displays "{}" instead of "a" value</span></pre></div>
<p dir="auto">Just by adding <code class="notranslate">console.log(msgs)</code>, it makes it work.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const foo = async (...msgs) =&gt; {
  console.log(msgs);
  let t = await msgs[0];
  console.log(t);
}

foo('a'); // displays &quot;a&quot; "><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-en">foo</span> <span class="pl-c1">=</span> <span class="pl-k">async</span> <span class="pl-kos">(</span>...<span class="pl-s1">msgs</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">msgs</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">let</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">msgs</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">t</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s">'a'</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// displays "a" </span></pre></div>
<p dir="auto">Basically, adding <code class="notranslate">console.log(msgs)</code> moves the args to a distinct array:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="for (var _len = arguments.length, msgs = Array(_len), _key = 0; _key &lt; _len; _key++) {
    msgs[_key] = arguments[_key];
  }"><pre class="notranslate"><code class="notranslate">for (var _len = arguments.length, msgs = Array(_len), _key = 0; _key &lt; _len; _key++) {
    msgs[_key] = arguments[_key];
  }
</code></pre></div>
<p dir="auto">In the repl:<br>
<a href="https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=false&amp;code=const%20asyncArg%20%3D%20async%20(msg)%20%3D%3E%20%7B%0D%0A%20%20let%20t%20%3D%20await%20msg%3B%0D%0A%20%20console.log(t)%3B%0D%0A%7D%0D%0A%0D%0Aconst%20asyncArgs%20%3D%20async%20(...msgs)%20%3D%3E%20%7B%0D%0A%20%20let%20t%20%3D%20await%20msgs%5B0%5D%3B%0D%0A%20%20console.log(t)%3B%0D%0A%7D%0D%0A%0D%0AasyncArg('1')%3B%0D%0AasyncArgs('2')%3B%0D%0A" rel="nofollow">https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=false&amp;code=const%20asyncArg%20%3D%20async%20(msg)%20%3D%3E%20%7B%0D%0A%20%20let%20t%20%3D%20await%20msg%3B%0D%0A%20%20console.log(t)%3B%0D%0A%7D%0D%0A%0D%0Aconst%20asyncArgs%20%3D%20async%20(...msgs)%20%3D%3E%20%7B%0D%0A%20%20let%20t%20%3D%20await%20msgs%5B0%5D%3B%0D%0A%20%20console.log(t)%3B%0D%0A%7D%0D%0A%0D%0AasyncArg('1')%3B%0D%0AasyncArgs('2')%3B%0D%0A</a></p>