@@ -9,6 +9,7 @@ import YAML = require('js-yaml');
9
9
import minimatch = require ( 'minimatch' ) ;
10
10
import os = require ( 'os' ) ;
11
11
import path = require ( 'path' ) ;
12
+ import semver = require ( 'semver' ) ;
12
13
import util = require ( 'util' ) ;
13
14
import yargs = require ( 'yargs' ) ;
14
15
import cdkUtil = require ( '../lib/util' ) ;
@@ -469,7 +470,7 @@ async function initCommandLine() {
469
470
470
471
const response = await fs.readJson(outfile);
471
472
debug(response);
472
- return response;
473
+ return versionCheckResponse( response) ;
473
474
} finally {
474
475
debug('Removing outdir', outdir);
475
476
await fs.remove(outdir);
@@ -508,7 +509,37 @@ async function initCommandLine() {
508
509
});
509
510
}
510
511
}
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
+ }
511
541
542
+ return response;
512
543
}
513
544
514
545
/**
0 commit comments