dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
967 stars 33 forks source link

stack trace tranucated #150

Open sigmaSd opened 1 year ago

sigmaSd commented 1 year ago

Don't know if its a dax or a deno issue, or if its the way things works But It would be great if this can be fixed

code:

import { $ } from "https://deno.land/x/dax@0.32.0/mod.ts";
await $`donotexistbinary`;

result

Uncaught Error: Command not found: donotexistbinary
    at resolveCommand (https://deno.land/x/dax@0.32.0/src/shell.ts:773:11)
    at eventLoopTick (ext:core/01_core.js:182:11)
    at async executeCommandArgs (https://deno.land/x/dax@0.32.0/src/shell.ts:5
71:27)
    at async executeSimpleCommand (https://deno.land/x/dax@0.32.0/src/shell.ts
:560:10)
    at async executeSequentialList (https://deno.land/x/dax@0.32.0/src/shell.t
s:386:20)
    at async spawn (https://deno.land/x/dax@0.32.0/src/shell.ts:375:18)
    at async CommandChild.pipedStdoutBuffer (https://deno.land/x/dax@0.32.0/sr
c/command.ts:572:20)

The stack doesn't reach to user code

sigmaSd commented 1 year ago

Actually this issue is annoying in practice, when I get such errors, I don't know here to look, and I have to add logs everywhere

I wonder if this is just a javascript limitation

sigmaSd commented 1 year ago

At least I found a workaround , set this somewhere at the start $.setPrintCommand(true); Maybe this should be mentioned in the docs, its useful so far

dsherret commented 1 year ago

Probably this is https://github.com/denoland/deno/issues/18946

Here's a small reproduction:

async function a() {
  await new Promise((resolve, reject) => {
    setTimeout(() => {
      reject(new Error("test"));
    }, 20);
  });
}

try {
  await a();
} catch (err) {
  console.log(err.stack);
}

Edit: No this is wrong.

sigmaSd commented 1 year ago

Maybe this is related https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#improving_stack_trace

dsherret commented 5 months ago

Probably Error.captureStackTrace could be used here to improve the stack trace. I just did something similar in https://github.com/dsherret/dax/pull/236

I'll try to look into it soon.

dsherret commented 3 months ago

I opened https://github.com/denoland/deno/issues/23146