react-scanner icon indicating copy to clipboard operation
react-scanner copied to clipboard

Remove exit(1) when no files found to scan

Open Janey2022 opened this issue 2 years ago • 6 comments

Janey2022 avatar Feb 02 '23 04:02 Janey2022

With the origin logic, if I run it in the cases that contains several dirs, it will break when found one has no matched file to scan.

Janey2022 avatar Feb 02 '23 04:02 Janey2022

It seems not a good approach. But still need to handle the issue when the loop exit in some cases.

Janey2022 avatar Feb 02 '23 06:02 Janey2022

How about throwing an exception in this case?

That way, we can catch the error with a try{} catch(){}

FelipeNasci avatar Feb 12 '23 23:02 FelipeNasci

How about throwing an exception in this case?

That way, we can catch the error with a try{} catch(){}

Good point, yes, if we use process.exit instead of exception, try catch can't catch process.exit(1). Should throw exception instead.

Janey2022 avatar Feb 13 '23 07:02 Janey2022

Fixes https://github.com/moroshko/react-scanner/issues/68

gyfchong avatar Jun 16 '23 04:06 gyfchong

For those waiting for this to merge; we use the following monkey patch at work. 🐒

  {
    const old_exit = process.exit;
    // @ts-ignore monkey patching
    process.exit = () => {};

    await scanner.run(/* ...code... */);

    process.exit = old_exit;
  }

JulianNymark avatar Feb 14 '24 12:02 JulianNymark