fuse-box-typechecker icon indicating copy to clipboard operation
fuse-box-typechecker copied to clipboard

How to catch runSync() exception

Open mickaelmartinsdev opened this issue 7 years ago • 5 comments

Hi, I want to catch 'exception' when TypeHelper throws exception. How I can do that ?

try{ testSync.runSync(); }catch(error) { console.log('error : '+ error); }

Thank-you

mickaelmartinsdev avatar Feb 26 '18 15:02 mickaelmartinsdev

the throwOnError options just exits node process with error 1, not 0 (success), to make something like travis to react. To know if error happend during sync the easier, to stop transpiling/nw build, just skip the throwOn options and check how many errors.

var TypeHelper = require('./dist/commonjs/index.js').TypeHelper

// sync run
let checkerSync = TypeHelper({
    tsConfig: './tsconfig.json',
    basePath: './',
    tsLint: './tslint.json',
    name: 'checkerSync'
});
let noErrors = checkerSync.runSync()
if (noErrors) {
    console.log('on no, I have: ' + noErrors + ' errors');
} else {
    console.log('all OK :-)');
}


@mickaelmartinsdev Does this help you issue ?

vegarringdal avatar Feb 26 '18 15:02 vegarringdal

Documentation needs to be clearer for standard test cases

jpike88 avatar Apr 21 '18 07:04 jpike88

@vegarringdal actually this is a big issue now I'm trying to pipe error output to somewhere else.

Returning a number isn't enough, it should be an array of strings. If length 0, then 0 errors.

jpike88 avatar Jan 19 '21 14:01 jpike88

I didnt see this before now. We need to create a another function so we dont make a breaking change

vegarringdal avatar Jan 19 '21 17:01 vegarringdal

image

added a getresult function

https://github.com/fuse-box/fuse-box-typechecker/blob/master/src/index.ts#L80-L83

please make a PR with edits to this function with the array data you would like to see

https://github.com/fuse-box/fuse-box-typechecker/blob/d9b9fbb71dd3277ccabfc8e1a6b78d8f6b5f465d/src/printResult.ts#L13-L58

vegarringdal avatar Jan 19 '21 17:01 vegarringdal