denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.44k stars 5.24k forks source link

Runtime references deno-specific flag in error log #15105

Open cd-work opened 2 years ago

cd-work commented 2 years ago

When using deno_runtime and calling execute_main_module, the function will return an error if it is lacking permissions to access external IO, when printing this error it will look something like this:

Error: Requires write access to "./duplicates.txt", run again with the --allow-write flag

The issue with this is that the --allow-write flag is specific to Deno's CLI and thus might confuse users when deno_runtime is embedded in another application.

I've tried to work around this by using get_custom_error_class and checking if it is Some("PermissionDenied"), which it should be according to the source code. However this always returns None, despite the error being created through custom_error, so I'm not sure that function is working properly?

cd-work commented 2 years ago

Turns out since the error is passed through the JS boundary, the original error obviously can't be accessed with get_custom_error_class anymore.

I feel like the most reasonable solution would likely be to set this error during startup in some way? This might not be the only deno CLI specific error though, so I'm not sure if a wider-reaching solution is necessary.