1

Q: how to ignore errors in Visual Studio Custom Build Steps & continue with the Build process?

In my case, I have a NodeJS script which exec's an executable which may or may not yet be present, as it will be constructed by the first successful Build run. This is a bootstrap script, faking it until that binary does deliver.

Hence, errors are to be expected in there, all of whom are caught by the NodeJS script and handled by 'faking it'.

The problem is that Visual Studio 2019 aborts the Build process after running this script when it observes any errors being reported by it as it logs the exec (or rather: process.execFileSync) output. Doesn't seem to matter if I log to stderr or stdout.

Not so relevant, but for the curious folks: here's that NodeJS script. Rough & Ready.

Note: unimportant parts are snipped for brevity: [...]. The full script is at @@@@

[...]
if (fs.existsSync(replCfile)) {
    fs.unlinkSync(replCfile);
}
[...]
try {
    if (fs.existsSync(mutoolExe)) {
        const stdout = execFileSync(mutoolExe, ['qjsc', '-v', '-c', '-o', replCfile, replJSfile]);
        console.log(stdout);
        if (fs.existsSync(replCfile)) {
            console.log("Successfully generated the repl C source file from repl.js");
        }
        else { 
          bootstrap();
        }
    }
    else {
        bootstrap();
    }
} catch (ex) {
    // Note this bit; it'll show up in the answer again!
    console.log("COMPILE FAILED:", ex);
    bootstrap(true);
}
[...]
function bootstrap(forced) {
    if (forced) {
        forced = "FORCED";
    }
    if (!fs.existsSync(replCfile) || forced) {
        console.log(`BOOSTRAPPING ${ forced }: faking an empty repl C source file`);
        fs.writeFileSync(replCfile, `
[...]
`, 'utf8');
    }
[...]
    process.exit(0);
}

Investigated: the stuff I tried & looked at

Curious observations (Hints towards an answer)

Whatever I do, it always ends up either as:

  • ✅ no error what-so-ever, ✅ happy Build and we're good ✅.

    This happens ONLY after nuking the compiled binaries, i.e. destroying that muToolExe the NodeJS script is looking for and trying to exec.

    Or when I take out that execFileSync call, thus ruining the bootstrap script.

  • ❌ errors galore, ❌ Build aborted immediately, ❌ no good ❌.

    The only variable here being how many errors you'll get reported in the Visual Studio Errors tab. (Of course, you can see those in your Output tab too, but depending on what you just did and messed with, you get either 1(one) error or 2(two). Never (0)zero.

BTW, which version of DevStudio are you using?

v16.10.2 - that's the latest update of DevStud2019 at the time of writing.

I suspect all 2019 versions suffer from this, though. I don't want to downgrade just to verify this, so YMMV.

Ger Hobbelt
  • 1,126
  • 1
  • 11
  • 16

1 Answers1

2

A: Visual Studio 2019 "sniffs" your Output looking for errors to report. (Or so it seems...)

The discovery that made it all go away and resolve my issues with those pesky error reports which I wanted DevStudio to ignore entirely, was the notion that perhaps Visual Studio is somehow trying to 'parse' the stderr/stdout output produced by my Custom Build Step.

So I went and tweaked my Custom Build Step command script (see question above) a little bit.

Here's the original bit from above:

[...]
} catch (ex) {
    // Note this bit; it'll show up in the answer again!
    console.log("COMPILE FAILED:", ex);
    bootstrap(true);
}
[...]

and here is how it looks right now, where *POOF!* all my trouble has gone away:

[...]
} catch (ex) {
    //console.log("COMPILE FAILED:", ex);
    let errmsg = `COMPILE FAILED: ${ex}`;
    console.log(errmsg.replace(/Error/ig, 'Warning'));
    bootstrap(true);
}
[...]

What that does is take the execFileSync output and filter it before it is output to stdout, replacing every 'error' in there with a benign 'warning' (didn't want to discard that output for diagnostics reasons!)

!

Conclusion: make sure your Custom Build Step never says "error" anywhere

That's what that .replace(/Error/ig, 'Warning') does for my scenario. My output currently looks something like this:

1>COMPILE FAILED : warning : Command failed: Z:\lib\tooling\qiqqa\MuPDF\platform\win32\bin\Debug-Unicode-32bit-x86\mutool.exe qjsc -v -c -o Z:\lib\tooling\qiqqa\MuPDF\platform\win32\..\..\scripts\libQuickJS\qjsrepl.c Z:\lib\tooling\qiqqa\MuPDF\platform\win32\..\..\scripts\libQuickJS\../../thirdparty/owemdjee/QuickJS/repl.js
1>BOOSTRAPPING FORCED: faking an empty repl C source file
1>BOOSTRAPPING FORCED: faking an empty calc C source file

and Visual Studio 2019 is a happy camper again, completing Builds successfully and finally allowing this bootstrap mechanism in the Project to work as intended: fake it on the first run after cleanup, then run the (previously built) executable to produce the generated content.

BTW, that .replace(/Error/ig, 'Warning') indeed has the execFileSync failure show as a Warning item now! Which tells me that DevStud is indeed looking into my entire Output on the prowl for errors to report and abort on. Haven't found that info anywhere though, so would love if y'all can point me to references re this!

YMMV & Sayonara

While the SO links/solutions referenced in the question above MAY still work for Pre/Post Build Steps, they certainly don't for Custom Build Steps.

Hope this helps anyone who's stepped into the same tarpit as I did. I picked Custom Build Steps as those include Input and Output file lists and thus should act as a decent part of the build dependency chain (contrasting Pre/Post-Build Steps), but then the info got a bit thin on the ground...

Enjoy. This cost too much time to dig up, so let's pay this forward and hope Google/Bing/Duck help y'all (and me, next time I run into this and forgot how exactly to...).

Ger Hobbelt
  • 1,126
  • 1
  • 11
  • 16
  • 1
    Thank you for this. I was running a Custom Build Tool within a VC++ project in Visual Studio 2022, and kept having the entire build fail whenever the Custom Build Tool failed. In my case the Custom Build Tool ran `link.exe` to create a resource-only DLL for event logging. The event logging service can lock this DLL causing `link.exe` to fail to overwrite it. Now I run `link` followed by ` > nul 2>&1` to redirect all linker console output to `nul`. Finally I run `VERIFY > nul` to reset `ERRORLEVEL`. Now my builds succeed even when the Event log service is locking the resource DLL. – MikeOnline Oct 12 '22 at 23:55