@@ -9,6 +9,7 @@ import YAML = require('js-yaml');
99import minimatch = require ( 'minimatch' ) ;
1010import os = require ( 'os' ) ;
1111import path = require ( 'path' ) ;
12+ import semver = require ( 'semver' ) ;
1213import util = require ( 'util' ) ;
1314import yargs = require ( 'yargs' ) ;
1415import cdkUtil = require ( '../lib/util' ) ;
@@ -469,7 +470,7 @@ async function initCommandLine() {
469470
470471 const response = await fs.readJson(outfile);
471472 debug(response);
472- return response;
473+ return versionCheckResponse( response) ;
473474 } finally {
474475 debug('Removing outdir', outdir);
475476 await fs.remove(outdir);
@@ -508,7 +509,37 @@ async function initCommandLine() {
508509 });
509510 }
510511 }
512+ }
513+
514+ /**
515+ * Look at the type of response we get and upgrade it to the latest expected version
516+ */
517+ function versionCheckResponse(response: cxapi.SynthesizeResponse): cxapi.SynthesizeResponse {
518+ if (!response.version) {
519+ // tslint:disable-next-line:max-line-length
520+ throw new Error(` CDK Framework >= $ { cxapi . PROTO_RESPONSE_VERSION } is required in order to interact with this version of the Toolkit . `);
521+ }
522+
523+ const frameworkVersion = semver.coerce(response.version);
524+ const toolkitVersion = semver.coerce(cxapi.PROTO_RESPONSE_VERSION);
525+
526+ // Should not happen, but I don't trust this library 100% either, so let's check for it to be safe
527+ if (!frameworkVersion || !toolkitVersion) { throw new Error('SemVer library could not parse versions'); }
528+
529+ if (semver.gt(frameworkVersion, toolkitVersion)) {
530+ throw new Error(` CDK Toolkit >= $ { response . version } is required in order to interact with this program . `);
531+ }
532+
533+ if (semver.lt(frameworkVersion, toolkitVersion)) {
534+ // Toolkit protocol is newer than the framework version, and we KNOW the
535+ // version. This is a scenario in which we could potentially do some
536+ // upgrading of the response in the future.
537+ //
538+ // For now though, we simply reject old responses.
539+ throw new Error(` CDK Framework >= $ { cxapi . PROTO_RESPONSE_VERSION } is required in order to interact with this version of the Toolkit . `);
540+ }
511541
542+ return response;
512543 }
513544
514545 /**
0 commit comments