@jsii/kernel 1.67.0 → 1.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/kernel.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  import * as api from './api';
2
+ export declare const enum JsiiErrorType {
3
+ JSII_FAULT = "@jsii/kernel.Fault",
4
+ RUNTIME_ERROR = "@jsii/kernel.RuntimeError"
5
+ }
6
+ export interface JsiiError extends Error {
7
+ readonly name: JsiiErrorType;
8
+ }
9
+ export declare class JsiiFault extends Error implements JsiiError {
10
+ readonly name = JsiiErrorType.JSII_FAULT;
11
+ constructor(message: string);
12
+ }
13
+ export declare class RuntimeError extends Error implements JsiiError {
14
+ readonly name = JsiiErrorType.RUNTIME_ERROR;
15
+ constructor(message: string);
16
+ }
2
17
  export declare class Kernel {
3
18
  callbackHandler: (callback: api.Callback) => any;
4
19
  /**
package/lib/kernel.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Kernel = void 0;
3
+ exports.Kernel = exports.RuntimeError = exports.JsiiFault = void 0;
4
4
  const spec = require("@jsii/spec");
5
5
  const spec_1 = require("@jsii/spec");
6
6
  const cp = require("child_process");
@@ -16,6 +16,20 @@ const objects_1 = require("./objects");
16
16
  const onExit = require("./on-exit");
17
17
  const wire = require("./serialization");
18
18
  const tar = require("./tar-cache");
19
+ class JsiiFault extends Error {
20
+ constructor(message) {
21
+ super(message);
22
+ this.name = "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */;
23
+ }
24
+ }
25
+ exports.JsiiFault = JsiiFault;
26
+ class RuntimeError extends Error {
27
+ constructor(message) {
28
+ super(message);
29
+ this.name = "@jsii/kernel.RuntimeError" /* JsiiErrorType.RUNTIME_ERROR */;
30
+ }
31
+ }
32
+ exports.RuntimeError = RuntimeError;
19
33
  class Kernel {
20
34
  /**
21
35
  * Creates a jsii kernel object.
@@ -48,7 +62,7 @@ class Kernel {
48
62
  var _a, _b, _c;
49
63
  this._debug('load', req);
50
64
  if ('assembly' in req) {
51
- throw new Error('`assembly` field is deprecated for "load", use `name`, `version` and `tarball` instead');
65
+ throw new JsiiFault('`assembly` field is deprecated for "load", use `name`, `version` and `tarball` instead');
52
66
  }
53
67
  const pkgname = req.name;
54
68
  const pkgver = req.version;
@@ -58,7 +72,7 @@ class Kernel {
58
72
  // module exists, verify version
59
73
  const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
60
74
  if (epkg.version !== pkgver) {
61
- throw new Error(`Multiple versions ${pkgver} and ${epkg.version} of the ` +
75
+ throw new JsiiFault(`Multiple versions ${pkgver} and ${epkg.version} of the ` +
62
76
  `package '${pkgname}' cannot be loaded together since this is unsupported by ` +
63
77
  'some runtime environments');
64
78
  }
@@ -101,7 +115,7 @@ class Kernel {
101
115
  assmSpec = this._debugTime(() => (0, spec_1.loadAssemblyFromPath)(packageDir), `loadAssemblyFromPath(${packageDir})`);
102
116
  }
103
117
  catch (e) {
104
- throw new Error(`Error for package tarball ${req.tarball}: ${e.message}`);
118
+ throw new JsiiFault(`Error for package tarball ${req.tarball}: ${e.message}`);
105
119
  }
106
120
  // load the module and capture its closure
107
121
  const closure = this._debugTime(() => this.require(packageDir), `require(${packageDir})`);
@@ -119,11 +133,11 @@ class Kernel {
119
133
  // module exists, verify version
120
134
  const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
121
135
  if (!epkg.bin) {
122
- throw new Error('There is no bin scripts defined for this package.');
136
+ throw new JsiiFault('There is no bin scripts defined for this package.');
123
137
  }
124
138
  const scriptPath = epkg.bin[req.script];
125
139
  if (!epkg.bin) {
126
- throw new Error(`Script with name ${req.script} was not defined.`);
140
+ throw new JsiiFault(`Script with name ${req.script} was not defined.`);
127
141
  }
128
142
  const result = cp.spawnSync(path.join(packageDir, scriptPath), (_a = req.args) !== null && _a !== void 0 ? _a : [], {
129
143
  encoding: 'utf-8',
@@ -143,7 +157,7 @@ class Kernel {
143
157
  signal: result.signal,
144
158
  };
145
159
  }
146
- throw new Error(`Package with name ${req.assembly} was not loaded.`);
160
+ throw new JsiiFault(`Package with name ${req.assembly} was not loaded.`);
147
161
  }
148
162
  create(req) {
149
163
  return this._create(req);
@@ -160,7 +174,7 @@ class Kernel {
160
174
  this._debug('sget', symbol);
161
175
  const ti = this._typeInfoForProperty(property, fqn);
162
176
  if (!ti.static) {
163
- throw new Error(`property ${symbol} is not static`);
177
+ throw new JsiiFault(`property ${symbol} is not static`);
164
178
  }
165
179
  const prototype = this._findSymbol(fqn);
166
180
  const value = this._ensureSync(`property ${property}`, () => prototype[property]);
@@ -175,10 +189,10 @@ class Kernel {
175
189
  this._debug('sset', symbol);
176
190
  const ti = this._typeInfoForProperty(property, fqn);
177
191
  if (!ti.static) {
178
- throw new Error(`property ${symbol} is not static`);
192
+ throw new JsiiFault(`property ${symbol} is not static`);
179
193
  }
180
194
  if (ti.immutable) {
181
- throw new Error(`static property ${symbol} is readonly`);
195
+ throw new JsiiFault(`static property ${symbol} is readonly`);
182
196
  }
183
197
  const prototype = this._findSymbol(fqn);
184
198
  this._ensureSync(`property ${property}`, () => (prototype[property] = this._toSandbox(value, ti, `assigned to static property ${symbol}`)));
@@ -209,7 +223,7 @@ class Kernel {
209
223
  const { instance, fqn, interfaces } = this.objects.findObject(objref);
210
224
  const propInfo = this._typeInfoForProperty(req.property, fqn, interfaces);
211
225
  if (propInfo.immutable) {
212
- throw new Error(`Cannot set value of immutable property ${req.property} to ${req.value}`);
226
+ throw new JsiiFault(`Cannot set value of immutable property ${req.property} to ${req.value}`);
213
227
  }
214
228
  const propertyToSet = this._findPropertyTarget(instance, property);
215
229
  this._ensureSync(`property '${objref[api_1.TOKEN_REF]}.${propertyToSet}'`, () => (instance[propertyToSet] = this._toSandbox(value, propInfo, `assigned to property ${fqn}.${property}`)));
@@ -223,7 +237,7 @@ class Kernel {
223
237
  const { ti, obj, fn } = this._findInvokeTarget(objref, method, args);
224
238
  // verify this is not an async method
225
239
  if (ti.async) {
226
- throw new Error(`${method} is an async method, use "begin" instead`);
240
+ throw new JsiiFault(`${method} is an async method, use "begin" instead`);
227
241
  }
228
242
  const fqn = (0, objects_1.jsiiTypeFqn)(obj);
229
243
  const ret = this._ensureSync(`method '${objref[api_1.TOKEN_REF]}.${method}'`, () => {
@@ -240,11 +254,11 @@ class Kernel {
240
254
  this._debug('sinvoke', fqn, method, args);
241
255
  const ti = this._typeInfoForMethod(method, fqn);
242
256
  if (!ti.static) {
243
- throw new Error(`${fqn}.${method} is not a static method`);
257
+ throw new JsiiFault(`${fqn}.${method} is not a static method`);
244
258
  }
245
259
  // verify this is not an async method
246
260
  if (ti.async) {
247
- throw new Error(`${method} is an async method, use "begin" instead`);
261
+ throw new JsiiFault(`${method} is an async method, use "begin" instead`);
248
262
  }
249
263
  const prototype = this._findSymbol(fqn);
250
264
  const fn = prototype[method];
@@ -262,12 +276,12 @@ class Kernel {
262
276
  const args = (_a = req.args) !== null && _a !== void 0 ? _a : [];
263
277
  this._debug('begin', objref, method, args);
264
278
  if (this.syncInProgress) {
265
- throw new Error(`Cannot invoke async method '${req.objref[api_1.TOKEN_REF]}.${req.method}' while sync ${this.syncInProgress} is being processed`);
279
+ throw new JsiiFault(`Cannot invoke async method '${req.objref[api_1.TOKEN_REF]}.${req.method}' while sync ${this.syncInProgress} is being processed`);
266
280
  }
267
281
  const { ti, obj, fn } = this._findInvokeTarget(objref, method, args);
268
282
  // verify this is indeed an async method
269
283
  if (!ti.async) {
270
- throw new Error(`Method ${method} is expected to be an async method`);
284
+ throw new JsiiFault(`Method ${method} is expected to be an async method`);
271
285
  }
272
286
  const fqn = (0, objects_1.jsiiTypeFqn)(obj);
273
287
  const promise = fn.apply(obj, this._toSandboxValues(args, `async method ${fqn ? `${fqn}#` : ''}${method}`, ti.parameters));
@@ -288,7 +302,7 @@ class Kernel {
288
302
  this._debug('end', promiseid);
289
303
  const storedPromise = this.promises.get(promiseid);
290
304
  if (storedPromise == null) {
291
- throw new Error(`Cannot find promise with ID: ${promiseid}`);
305
+ throw new JsiiFault(`Cannot find promise with ID: ${promiseid}`);
292
306
  }
293
307
  const { promise, method } = storedPromise;
294
308
  let result;
@@ -298,7 +312,7 @@ class Kernel {
298
312
  }
299
313
  catch (e) {
300
314
  this._debug('promise error:', e);
301
- throw e;
315
+ throw new JsiiFault(e.message);
302
316
  }
303
317
  return {
304
318
  result: this._fromSandbox(result, (_a = method.returns) !== null && _a !== void 0 ? _a : 'void', `returned by async method ${method.name}`),
@@ -328,7 +342,7 @@ class Kernel {
328
342
  this._debug('complete', cbid, err, result);
329
343
  const cb = this.waiting.get(cbid);
330
344
  if (!cb) {
331
- throw new Error(`Callback ${cbid} not found`);
345
+ throw new JsiiFault(`Callback ${cbid} not found`);
332
346
  }
333
347
  if (err) {
334
348
  this._debug('completed with error:', err);
@@ -352,7 +366,7 @@ class Kernel {
352
366
  const assembly = this._assemblyFor(assemblyName);
353
367
  const targets = assembly.metadata.targets;
354
368
  if (!targets) {
355
- throw new Error(`Unexpected - "targets" for ${assemblyName} is missing!`);
369
+ throw new JsiiFault(`Unexpected - "targets" for ${assemblyName} is missing!`);
356
370
  }
357
371
  return { naming: targets };
358
372
  }
@@ -374,7 +388,7 @@ class Kernel {
374
388
  case spec.TypeKind.Class:
375
389
  case spec.TypeKind.Enum:
376
390
  const constructor = this._findSymbol(fqn);
377
- (0, objects_1.tagJsiiConstructor)(constructor, fqn, assm.metadata.version);
391
+ (0, objects_1.tagJsiiConstructor)(constructor, fqn);
378
392
  }
379
393
  }
380
394
  }
@@ -393,9 +407,9 @@ class Kernel {
393
407
  parameters: classType.initializer && classType.initializer.parameters,
394
408
  };
395
409
  case spec.TypeKind.Interface:
396
- throw new Error(`Cannot create an object with an FQN of an interface: ${fqn}`);
410
+ throw new JsiiFault(`Cannot create an object with an FQN of an interface: ${fqn}`);
397
411
  default:
398
- throw new Error(`Unexpected FQN kind: ${fqn}`);
412
+ throw new JsiiFault(`Unexpected FQN kind: ${fqn}`);
399
413
  }
400
414
  }
401
415
  _getPackageDir(pkgname) {
@@ -429,26 +443,26 @@ class Kernel {
429
443
  for (const override of overrides) {
430
444
  if (api.isMethodOverride(override)) {
431
445
  if (api.isPropertyOverride(override)) {
432
- throw new Error(overrideTypeErrorMessage);
446
+ throw new JsiiFault(overrideTypeErrorMessage);
433
447
  }
434
448
  if (methods.has(override.method)) {
435
- throw new Error(`Duplicate override for method '${override.method}'`);
449
+ throw new JsiiFault(`Duplicate override for method '${override.method}'`);
436
450
  }
437
451
  methods.add(override.method);
438
452
  this._applyMethodOverride(obj, objref, fqn, interfaces, override);
439
453
  }
440
454
  else if (api.isPropertyOverride(override)) {
441
455
  if (api.isMethodOverride(override)) {
442
- throw new Error(overrideTypeErrorMessage);
456
+ throw new JsiiFault(overrideTypeErrorMessage);
443
457
  }
444
458
  if (properties.has(override.property)) {
445
- throw Error(`Duplicate override for property '${override.property}'`);
459
+ throw new JsiiFault(`Duplicate override for property '${override.property}'`);
446
460
  }
447
461
  properties.add(override.property);
448
462
  this._applyPropertyOverride(obj, objref, fqn, interfaces, override);
449
463
  }
450
464
  else {
451
- throw new Error(overrideTypeErrorMessage);
465
+ throw new JsiiFault(overrideTypeErrorMessage);
452
466
  }
453
467
  }
454
468
  }
@@ -460,7 +474,7 @@ class Kernel {
460
474
  _applyPropertyOverride(obj, objref, typeFqn, interfaces, override) {
461
475
  // error if we can find a method with this name
462
476
  if (this._tryTypeInfoForMethod(override.property, typeFqn, interfaces)) {
463
- throw new Error(`Trying to override method '${override.property}' as a property`);
477
+ throw new JsiiFault(`Trying to override method '${override.property}' as a property`);
464
478
  }
465
479
  let propInfo = this._tryTypeInfoForProperty(override.property, typeFqn, interfaces);
466
480
  // if this is a private property (i.e. doesn't have `propInfo` the object has a key)
@@ -546,7 +560,7 @@ class Kernel {
546
560
  _applyMethodOverride(obj, objref, typeFqn, interfaces, override) {
547
561
  // error if we can find a property with this name
548
562
  if (this._tryTypeInfoForProperty(override.method, typeFqn, interfaces)) {
549
- throw new Error(`Trying to override property '${override.method}' as a method`);
563
+ throw new JsiiFault(`Trying to override property '${override.method}' as a method`);
550
564
  }
551
565
  let methodInfo = this._tryTypeInfoForMethod(override.method, typeFqn, interfaces);
552
566
  // If this is a private method (doesn't have methodInfo, key resolves on the object), we
@@ -645,7 +659,7 @@ class Kernel {
645
659
  if (!fn) {
646
660
  fn = instance[methodName];
647
661
  if (!fn) {
648
- throw new Error(`Cannot find ${methodName} on object`);
662
+ throw new JsiiFault(`Cannot find ${methodName} on object`);
649
663
  }
650
664
  }
651
665
  return { ti, obj: instance, fn };
@@ -655,7 +669,7 @@ class Kernel {
655
669
  const params = (_a = method === null || method === void 0 ? void 0 : method.parameters) !== null && _a !== void 0 ? _a : [];
656
670
  // error if args > params
657
671
  if (args.length > params.length && !(method && method.variadic)) {
658
- throw new Error(`Too many arguments (method accepts ${params.length} parameters, got ${args.length} arguments)`);
672
+ throw new JsiiFault(`Too many arguments (method accepts ${params.length} parameters, got ${args.length} arguments)`);
659
673
  }
660
674
  for (let i = 0; i < params.length; ++i) {
661
675
  const param = params[i];
@@ -666,19 +680,19 @@ class Kernel {
666
680
  } // No vararg was provided
667
681
  for (let j = i; j < params.length; j++) {
668
682
  if (!param.optional && params[j] === undefined) {
669
- throw new Error(`Unexpected 'undefined' value at index ${j - i} of variadic argument '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
683
+ throw new JsiiFault(`Unexpected 'undefined' value at index ${j - i} of variadic argument '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
670
684
  }
671
685
  }
672
686
  }
673
687
  else if (!param.optional && arg === undefined) {
674
- throw new Error(`Not enough arguments. Missing argument for the required parameter '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
688
+ throw new JsiiFault(`Not enough arguments. Missing argument for the required parameter '${param.name}' of type '${spec.describeTypeReference(param.type)}'`);
675
689
  }
676
690
  }
677
691
  }
678
692
  _assemblyFor(assemblyName) {
679
693
  const assembly = this.assemblies.get(assemblyName);
680
694
  if (!assembly) {
681
- throw new Error(`Could not find assembly: ${assemblyName}`);
695
+ throw new JsiiFault(`Could not find assembly: ${assemblyName}`);
682
696
  }
683
697
  return assembly;
684
698
  }
@@ -694,7 +708,7 @@ class Kernel {
694
708
  curr = curr[name];
695
709
  }
696
710
  if (!curr) {
697
- throw new Error(`Could not find symbol ${fqn}`);
711
+ throw new JsiiFault(`Could not find symbol ${fqn}`);
698
712
  }
699
713
  return curr;
700
714
  }
@@ -704,12 +718,12 @@ class Kernel {
704
718
  const moduleName = components[0];
705
719
  const assembly = this.assemblies.get(moduleName);
706
720
  if (!assembly) {
707
- throw new Error(`Module '${moduleName}' not found`);
721
+ throw new JsiiFault(`Module '${moduleName}' not found`);
708
722
  }
709
723
  const types = (_a = assembly.metadata.types) !== null && _a !== void 0 ? _a : {};
710
724
  const fqnInfo = types[fqn];
711
725
  if (!fqnInfo) {
712
- throw new Error(`Type '${fqn}' not found`);
726
+ throw new JsiiFault(`Type '${fqn}' not found`);
713
727
  }
714
728
  return fqnInfo;
715
729
  }
@@ -719,7 +733,7 @@ class Kernel {
719
733
  const addendum = interfaces && interfaces.length > 0
720
734
  ? ` or interface(s) ${interfaces.join(', ')}`
721
735
  : '';
722
- throw new Error(`Class ${fqn}${addendum} doesn't have a method '${methodName}'`);
736
+ throw new JsiiFault(`Class ${fqn}${addendum} doesn't have a method '${methodName}'`);
723
737
  }
724
738
  return ti;
725
739
  }
@@ -773,7 +787,7 @@ class Kernel {
773
787
  bases = (_a = interfaceTypeInfo.interfaces) !== null && _a !== void 0 ? _a : [];
774
788
  }
775
789
  else {
776
- throw new Error(`Type of kind ${typeInfo.kind} does not have properties`);
790
+ throw new JsiiFault(`Type of kind ${typeInfo.kind} does not have properties`);
777
791
  }
778
792
  for (const p of properties !== null && properties !== void 0 ? properties : []) {
779
793
  if (p.name === property) {
@@ -796,7 +810,7 @@ class Kernel {
796
810
  const addendum = interfaces && interfaces.length > 0
797
811
  ? ` or interface(s) ${interfaces.join(', ')}`
798
812
  : '';
799
- throw new Error(`Type ${fqn}${addendum} doesn't have a property '${property}'`);
813
+ throw new JsiiFault(`Type ${fqn}${addendum} doesn't have a property '${property}'`);
800
814
  }
801
815
  return typeInfo;
802
816
  }
@@ -831,7 +845,7 @@ class Kernel {
831
845
  parametersCopy.push(parametersCopy[parametersCopy.length - 1]);
832
846
  }
833
847
  if (xs.length > parametersCopy.length) {
834
- throw new Error(`Argument list (${JSON.stringify(xs)}) not same size as expected argument list (length ${parametersCopy.length})`);
848
+ throw new JsiiFault(`Argument list (${JSON.stringify(xs)}) not same size as expected argument list (length ${parametersCopy.length})`);
835
849
  }
836
850
  return xs.map((x, i) => boxUnbox(x, parametersCopy[i], `passed to parameter ${parametersCopy[i].name} of ${methodContext}`));
837
851
  }
@@ -863,6 +877,15 @@ class Kernel {
863
877
  try {
864
878
  return fn();
865
879
  }
880
+ catch (e) {
881
+ if (e.name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */) {
882
+ throw new JsiiFault(e);
883
+ }
884
+ // This error can be thrown by the kernel directly, or it can be
885
+ // thrown from user code. If the error comes from the kernel, then its name field will be populated;
886
+ // if the error comes from user code, the name field will not be populated.
887
+ throw new RuntimeError(e);
888
+ }
866
889
  finally {
867
890
  delete this.syncInProgress;
868
891
  }
package/lib/objects.d.ts CHANGED
@@ -17,7 +17,7 @@ export declare function objectReference(obj: unknown): api.ObjRef | undefined;
17
17
  /**
18
18
  * Set the JSII FQN for classes produced by a given constructor
19
19
  */
20
- export declare function tagJsiiConstructor(constructor: any, fqn: string, version: string): void;
20
+ export declare function tagJsiiConstructor(constructor: any, fqn: string): void;
21
21
  /**
22
22
  * Table of JSII objects
23
23
  *
package/lib/objects.js CHANGED
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectTable = exports.tagJsiiConstructor = exports.objectReference = exports.jsiiTypeFqn = void 0;
4
4
  const spec = require("@jsii/spec");
5
+ const assert = require("assert");
5
6
  const api = require("./api");
7
+ const kernel_1 = require("./kernel");
6
8
  const serialization_1 = require("./serialization");
7
9
  /**
8
10
  * Symbol under which we store the { type -> objid } map on object instances
@@ -13,9 +15,9 @@ const OBJID_SYMBOL = Symbol.for('$__jsii__objid__$');
13
15
  */
14
16
  const IFACES_SYMBOL = Symbol.for('$__jsii__interfaces__$');
15
17
  /**
16
- * Symbol we use to tag the constructor of a JSII class
18
+ * Symbol we use to tag constructors that are exported from a JSII module.
17
19
  */
18
- const JSII_RTTI_SYMBOL = Symbol.for('jsii.rtti');
20
+ const JSII_TYPE_FQN_SYMBOL = Symbol('$__jsii__fqn__$');
19
21
  /**
20
22
  * Get the JSII fqn for an object (if available)
21
23
  *
@@ -24,8 +26,7 @@ const JSII_RTTI_SYMBOL = Symbol.for('jsii.rtti');
24
26
  * information.
25
27
  */
26
28
  function jsiiTypeFqn(obj) {
27
- var _a;
28
- return (_a = obj.constructor[JSII_RTTI_SYMBOL]) === null || _a === void 0 ? void 0 : _a.fqn;
29
+ return obj.constructor[JSII_TYPE_FQN_SYMBOL];
29
30
  }
30
31
  exports.jsiiTypeFqn = jsiiTypeFqn;
31
32
  /**
@@ -72,15 +73,17 @@ function tagObject(obj, objid, interfaces) {
72
73
  /**
73
74
  * Set the JSII FQN for classes produced by a given constructor
74
75
  */
75
- function tagJsiiConstructor(constructor, fqn, version) {
76
- if (Object.prototype.hasOwnProperty.call(constructor, JSII_RTTI_SYMBOL)) {
77
- return;
76
+ function tagJsiiConstructor(constructor, fqn) {
77
+ if (Object.prototype.hasOwnProperty.call(constructor, JSII_TYPE_FQN_SYMBOL)) {
78
+ return assert(constructor[JSII_TYPE_FQN_SYMBOL] === fqn, `Unable to register ${constructor.name} as ${fqn}: it is already registerd with FQN ${constructor[JSII_TYPE_FQN_SYMBOL]}`);
78
79
  }
79
- Object.defineProperty(constructor, JSII_RTTI_SYMBOL, {
80
+ // Mark this constructor as exported from a jsii module, so we know we
81
+ // should be considering it's FQN as a valid exported type.
82
+ Object.defineProperty(constructor, JSII_TYPE_FQN_SYMBOL, {
80
83
  configurable: false,
81
84
  enumerable: false,
82
85
  writable: false,
83
- value: { fqn, version },
86
+ value: fqn,
84
87
  });
85
88
  }
86
89
  exports.tagJsiiConstructor = tagJsiiConstructor;
@@ -104,7 +107,7 @@ class ObjectTable {
104
107
  registerObject(obj, fqn, interfaces) {
105
108
  var _a;
106
109
  if (fqn === undefined) {
107
- throw new Error('FQN cannot be undefined');
110
+ throw new kernel_1.JsiiFault('FQN cannot be undefined');
108
111
  }
109
112
  const existingRef = objectReference(obj);
110
113
  if (existingRef) {
@@ -138,12 +141,12 @@ class ObjectTable {
138
141
  findObject(objref) {
139
142
  var _a;
140
143
  if (typeof objref !== 'object' || !(api.TOKEN_REF in objref)) {
141
- throw new Error(`Malformed object reference: ${JSON.stringify(objref)}`);
144
+ throw new kernel_1.JsiiFault(`Malformed object reference: ${JSON.stringify(objref)}`);
142
145
  }
143
146
  const objid = objref[api.TOKEN_REF];
144
147
  const obj = this.objects.get(objid);
145
148
  if (!obj) {
146
- throw new Error(`Object ${objid} not found`);
149
+ throw new kernel_1.JsiiFault(`Object ${objid} not found`);
147
150
  }
148
151
  // If there are "additional" interfaces declared on the objref, merge them
149
152
  // into the returned object. This is used to support client-side forced
@@ -170,7 +173,7 @@ class ObjectTable {
170
173
  */
171
174
  deleteObject({ [api.TOKEN_REF]: objid }) {
172
175
  if (!this.objects.delete(objid)) {
173
- throw new Error(`Object ${objid} not found`);
176
+ throw new kernel_1.JsiiFault(`Object ${objid} not found`);
174
177
  }
175
178
  }
176
179
  get count() {
@@ -204,7 +207,7 @@ class InterfaceCollection {
204
207
  addFromClass(fqn) {
205
208
  const ti = this.resolveType(fqn);
206
209
  if (!spec.isClassType(ti)) {
207
- throw new Error(`Expected a class, but received ${spec.describeTypeReference(ti)}`);
210
+ throw new kernel_1.JsiiFault(`Expected a class, but received ${spec.describeTypeReference(ti)}`);
208
211
  }
209
212
  if (ti.base) {
210
213
  this.addFromClass(ti.base);
@@ -222,7 +225,7 @@ class InterfaceCollection {
222
225
  addFromInterface(fqn) {
223
226
  const ti = this.resolveType(fqn);
224
227
  if (!spec.isInterfaceType(ti)) {
225
- throw new Error(`Expected an interface, but received ${spec.describeTypeReference(ti)}`);
228
+ throw new kernel_1.JsiiFault(`Expected an interface, but received ${spec.describeTypeReference(ti)}`);
226
229
  }
227
230
  if (!ti.interfaces) {
228
231
  return;
package/lib/recording.js CHANGED
@@ -47,7 +47,7 @@ function recordInteraction(kernel, inputOutputLogPath) {
47
47
  ok(value);
48
48
  })
49
49
  .catch((err) => {
50
- logOutput({ error: err.message });
50
+ logOutput({ error: err.message, name: err.name });
51
51
  fail(err);
52
52
  });
53
53
  });
@@ -56,8 +56,11 @@ function recordInteraction(kernel, inputOutputLogPath) {
56
56
  return ret;
57
57
  }
58
58
  catch (e) {
59
- logOutput({ error: e.message });
60
- throw e;
59
+ logOutput({ error: e.message, name: e.name });
60
+ if (e.type === "@jsii/kernel.RuntimeError" /* JsiiErrorType.RUNTIME_ERROR */) {
61
+ throw new kernel_1.RuntimeError(e.message);
62
+ }
63
+ throw new kernel_1.JsiiFault(e.message);
61
64
  }
62
65
  },
63
66
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsii/kernel",
3
- "version": "1.67.0",
3
+ "version": "1.68.0",
4
4
  "description": "kernel for jsii execution environment",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -31,19 +31,19 @@
31
31
  "package": "package-js"
32
32
  },
33
33
  "dependencies": {
34
- "@jsii/spec": "^1.67.0",
34
+ "@jsii/spec": "^1.68.0",
35
35
  "fs-extra": "^10.1.0",
36
36
  "lockfile": "^1.0.4",
37
37
  "tar": "^6.1.11"
38
38
  },
39
39
  "devDependencies": {
40
- "@scope/jsii-calc-base": "^1.67.0",
41
- "@scope/jsii-calc-lib": "^1.67.0",
40
+ "@scope/jsii-calc-base": "^1.68.0",
41
+ "@scope/jsii-calc-lib": "^1.68.0",
42
42
  "@types/fs-extra": "^9.0.13",
43
43
  "@types/lockfile": "^1.0.2",
44
44
  "@types/tar": "^6.1.2",
45
- "jest-expect-message": "^1.0.2",
46
- "jsii-build-tools": "^1.67.0",
45
+ "jest-expect-message": "^1.1.2",
46
+ "jsii-build-tools": "^1.68.0",
47
47
  "jsii-calc": "^3.20.120"
48
48
  }
49
49
  }