hoffi / gulp-msbuild

gulp-msbuild has moved to https://github.com/fluffynuts/gulp-msbuild.
MIT License
53 stars 44 forks source link

Error: no writecb in Transform class #56

Closed AArnott closed 7 years ago

AArnott commented 7 years ago

After upgrading from 0.2.20 to 0.4.7, my gulp script crashes with an unhandled exception:

Unhandled exception has occurred: Error
Error: no writecb in Transform class
    at afterTransform (f:\git\devcore\src\Node\node_modules\readable-stream\lib\_stream_transform.js:75:33)
    at TransformState.afterTransform (f:\git\devcore\src\Node\node_modules\readable-stream\lib\_stream_transform.js:59:12)
    at f:\git\devcore\src\Node\node_modules\gulp-msbuild\index.js:47:14
    at ChildProcess.<anonymous> (f:\git\devcore\src\Node\node_modules\gulp-msbuild\lib\msbuild-runner.js:57:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:886:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

This is my gulp task:

gulp.task('signAndLocalizeNode', ['buildNode', 'browserify'], function () {
    // We only sign on our Windows build box
    if (process.platform !== 'win32') {
        return;
    }
    var options = {
        targets: ['Build'],
        toolsVersion: 15.0,
        properties: {},
        nodeReuse: false,
        logCommand: false,
        stdout: false,
        stderr: true
    };
    if (cmdLine.argv.testSign) {
        options.properties.signtype = 'test';
    }
    if (cmdLine.argv.locType) {
        options.properties.locType = cmdLine.argv.locType;
        options.properties.loclanguages = 'VS';
    }
    if (Debug_1.Debug.diagVerbosityIsAtLeast(Debug_1.Debug.DebVerbosityOpt)) {
        options.logCommand = true;
        options.stdout = true;
    }
    var deferrer = q.defer();
    gulp.src('./MicroBuildSigning.sln')
        .pipe(msbuild(options))
        .on('end', function () {
        deferrer.resolve(null);
    });
    return deferrer.promise
        .then(function () {
        return gulp.src(config.allDefaultResourceJson, { base: config.tsOutputPath })
            .pipe(nls.createAdditionalLanguageFiles(config.supportedLanguages, config.localizationPath))
            .pipe(gulp.dest(config.tsOutputPath));
    });
});
AArnott commented 7 years ago

A bit of sleuthing on the internet suggests this error occurs when cb (or callback) is invoked more than once.

AArnott commented 7 years ago

The first time the callback is invoked when your error handler invokes your private callback which in turn fires the callback.

Then your close handler invokes your own private callback which eventually fires the original callback again.

hoffi commented 7 years ago

Yes, this indeed looks like an error. I assumed here that the "close" event will not trigger, when there was an "error" event, but the nodejs docs say, that this is not always the case.

Note that the 'exit' event may or may not fire after an error has occurred. If you are listening to both the 'exit' and 'error' events, it is important to guard against accidentally invoking handler functions multiple times.

AArnott commented 7 years ago

Thanks!