When running the dir-compare
package compare()
method inside a VSCode Extension it is not succeeding, while it does from a regular node script.
It doesn't seem to output any error. What is happening here? Is there a way to find the underlying error? Is this even possible? How do I proceed?
The code below results in outputting err {}
.
const path1 = 'C:/a';
const path2 = 'C:/b';
try
{
dircompare.compare(path1, path2)
.then(res => terminal.sendText( 'echo "res ' + JSON.stringify( res ) + '"' ))
.catch(error => terminal.sendText( 'echo "E2 ' + JSON.stringify( error ) + '"' ));
}
catch(e)
{
terminal.sendText( 'echo "err ' + JSON.stringify( e ) + '"' );
}
It seems that it is not possible to stringify()
and log a caught error object directly, but using err?.message
the error can be shown.
See: Why are my JS promise catch error objects empty?
The error that appeared was Cannot read properties of undefined (reading compare)
Apparently importing dir-compare
directly was not working
import dircompare from 'dir-compare';
Instead importing its methods:
import { compareSync } from 'dir-compare';
Then calling the method directly:
compareSync( path1, path2 );