ses 1.14.0 → 2.0.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/types.d.ts CHANGED
@@ -3,6 +3,8 @@
3
3
  * @module
4
4
  */
5
5
 
6
+ import '@endo/immutable-arraybuffer/shim.js';
7
+
6
8
  /* eslint-disable no-restricted-globals, vars-on-top, no-var */
7
9
 
8
10
  // It's academically tempting to define a hardened type, but TypeScript doesn't
@@ -187,20 +189,30 @@ export interface EvaluateOptions {
187
189
  __rejectSomeDirectEvalExpressions__?: boolean;
188
190
  }
189
191
 
192
+ interface Stringable {
193
+ toString(): string;
194
+ }
195
+
196
+ /** @deprecated */
197
+ type StringPayload = Stringable;
198
+
190
199
  /**
191
- * A call to the `details` template literal makes and returns a fresh details
192
- * token, which is a frozen empty object associated with the arguments of that
193
- * `details` template literal expression.
200
+ * A call to the {@link details} template literal makes and returns a fresh
201
+ * DetailsToken, which is a frozen empty object associated with the arguments of
202
+ * that expression.
194
203
  */
195
204
  export type DetailsToken = Record<any, never>;
196
- /** Either a plain string, or made by the `details` template literal tag. */
205
+ /**
206
+ * A plain string, or a {@link DetailsToken} from the {@link details} template
207
+ * literal tag.
208
+ */
197
209
  export type Details = string | DetailsToken;
198
210
 
199
211
  export interface AssertMakeErrorOptions {
200
212
  /**
201
213
  * Does not affect the error.name property. That remains determined by
202
214
  * the constructor. Rather, the `errorName` determines how this error is
203
- * identified in the causal console log's output.
215
+ * identified in an associated console's output.
204
216
  */
205
217
  errorName?: string;
206
218
 
@@ -280,10 +292,6 @@ export type AssertTypeof = AssertTypeofBigint &
280
292
  AssertTypeofSymbol &
281
293
  AssertTypeofUndefined;
282
294
 
283
- interface StringablePayload {
284
- toString(): string;
285
- }
286
-
287
295
  /**
288
296
  * TypeScript does not treat `AggregateErrorConstructor` as a subtype of
289
297
  * `ErrorConstructor`, which makes sense because their constructors
@@ -307,48 +315,44 @@ export type GenericErrorConstructor =
307
315
  export type Raise = (reason: Error) => void;
308
316
 
309
317
  /**
310
- * Makes and returns an `assert` function object that shares the bookkeeping
311
- * state defined by this module with other `assert` function objects made by
312
- * `makeAssert`. This state is per-module-instance and is exposed by the
313
- * `loggedErrorHandler` above. We refer to `assert` as a "function object"
314
- * because it can be called directly as a function, but also has methods that
315
- * can be called.
318
+ * Makes and returns an `assert` function object that shares the
319
+ * per-module-instance bookkeeping state defined by this module with other
320
+ * `assert` function objects made by `makeAssert`. We refer to `assert` as a
321
+ * "function object" because it can be called directly as a function, but also
322
+ * has callable methods of its own.
316
323
  *
317
- * If `optRaise` is provided, the returned `assert` function object will call
318
- * `optRaise(reason)` before throwing the error. This enables `optRaise` to
319
- * engage in even more violent termination behavior, like terminating the vat,
320
- * that prevents execution from reaching the following throw. However, if
321
- * `optRaise` returns normally, which would be unusual, the throw following
322
- * `optRaise(reason)` would still happen.
324
+ * If `raise` is provided, the returned `assert` function object will call
325
+ * `raise(reason)` before throwing an assertion-failure error. This enables
326
+ * `raise` to engage in even more violent termination behavior, like process
327
+ * termination, that prevents execution from reaching the following throw.
328
+ * However, if `raise(reason)` returns normally, which would be unusual, that
329
+ * throw still happens.
323
330
  */
324
- // Behold: recursion.
325
331
  // eslint-disable-next-line no-use-before-define
326
332
  export type MakeAssert = (raise?: Raise, unredacted?: boolean) => Assert;
327
333
 
328
334
  export type BaseAssert = (
329
- /** The truthy/falsy value we're testing */
330
- flag: any,
331
- /** The details of what was asserted */
335
+ /** The condition whose truthiness is being asserted */
336
+ condition: any,
337
+ /** The details associated with assertion failure (falsy condition) */
332
338
  details?: Details,
333
339
  /** An optional alternate error constructor to use */
334
340
  errConstructor?: GenericErrorConstructor,
335
341
  options?: AssertMakeErrorOptions,
336
- ) => asserts flag;
342
+ ) => asserts condition;
337
343
 
338
344
  export interface AssertionFunctions extends BaseAssert {
339
345
  typeof: AssertTypeof;
340
346
 
341
347
  /**
342
- * The `assert.equal` method
343
- *
344
- * Assert that two values must be `Object.is`.
348
+ * Assert that two values are the same as observed by `Object.is`.
345
349
  */
346
350
  equal<T>(
347
351
  /** What we received */
348
352
  actual: unknown,
349
353
  /** What we wanted */
350
354
  expected: T,
351
- /** The details of what was asserted */
355
+ /** The details associated with assertion failure (`Object.is` returning false) */
352
356
  details?: Details,
353
357
  /** An optional alternate error constructor to use */
354
358
  errConstructor?: GenericErrorConstructor,
@@ -356,12 +360,9 @@ export interface AssertionFunctions extends BaseAssert {
356
360
  ): asserts actual is T;
357
361
 
358
362
  /**
359
- * The `assert.string` method.
360
- *
363
+ * Assert that a value is a primitive string.
361
364
  * `assert.string(v)` is equivalent to `assert.typeof(v, 'string')`. We
362
365
  * special case this one because it is the most frequently used.
363
- *
364
- * Assert an expected typeof result.
365
366
  */
366
367
  string(
367
368
  specimen: any,
@@ -370,14 +371,9 @@ export interface AssertionFunctions extends BaseAssert {
370
371
  ): asserts specimen is string;
371
372
 
372
373
  /**
373
- * The `assert.fail` method.
374
- *
375
- * Fail an assertion, recording full details to the console and
376
- * raising an exception with a message in which `details` substitution values
377
- * have been redacted.
378
- *
379
- * The optional `optDetails` can be a string for backwards compatibility
380
- * with the nodejs assertion library.
374
+ * Fail an assertion, raising an exception with a `message` in which unquoted
375
+ * `details` substitution values may have been redacted into `typeof` types
376
+ * but are still available for logging to an associated console.
381
377
  */
382
378
  fail(
383
379
  /** The details of what was asserted */
@@ -390,11 +386,11 @@ export interface AssertionFunctions extends BaseAssert {
390
386
 
391
387
  export interface AssertionUtilities {
392
388
  /**
393
- * Aka the `makeError` function as imported from `@endo/errors`
394
- *
395
- * Recording unredacted details for the console.
389
+ * Create an error with a `message` in which unquoted {@link details}
390
+ * substitution values may have been redacted into lossy `typeof` output but
391
+ * are still available for logging to an associated console.
396
392
  */
397
- error(
393
+ makeError(
398
394
  /** The details of what was asserted */
399
395
  details?: Details,
400
396
  /** An optional alternate error constructor to use */
@@ -403,43 +399,27 @@ export interface AssertionUtilities {
403
399
  ): Error;
404
400
 
405
401
  /**
406
- * Aka the `annotateError` function as imported from `@endo/errors`
407
- *
408
- * Annotate an error with details, potentially to be used by an
409
- * augmented console such as the causal console of `console.js`, to
410
- * provide extra information associated with logged errors.
402
+ * Associate `details` with `error`, potentially to be logged by an associated
403
+ * console for providing extra information about the error.
411
404
  */
412
405
  note(error: Error, details: Details): void;
413
406
 
414
407
  /**
415
- * Use the `details` function as a template literal tag to create
416
- * informative error messages. The assertion functions take such messages
417
- * as optional arguments:
418
- * ```js
419
- * assert(sky.isBlue(), details`${sky.color} should be "blue"`);
420
- * ```
421
- * or following the normal convention to locally rename `details` to `X`
422
- * and `quote` to `q` like `const { details: X, quote: q } = assert;`:
423
- * ```js
424
- * assert(sky.isBlue(), X`${sky.color} should be "blue"`);
425
- * ```
408
+ * Use as a template literal tag to create an opaque {@link DetailsToken} for
409
+ * use with other assertion functions that might redact unquoted substitution
410
+ * values (i.e., those that are not output from the {@link quote} function)
411
+ * into lossy `typeof` output but still preserve them for logging to an
412
+ * associated console.
413
+ *
414
+ * The normal convention is to locally rename `details` to `X` like
415
+ * `const { details: X, quote: q, Fail } = assert;`.
426
416
  * However, note that in most cases it is preferable to instead use the `Fail`
427
- * template literal tag (which has the same input signature as `details`
428
- * but automatically creates and throws an error):
417
+ * template literal tag (which has the same input signature but automatically
418
+ * creates and throws an error):
429
419
  * ```js
430
420
  * sky.isBlue() || Fail`${sky.color} should be "blue"`;
431
421
  * ```
432
422
  *
433
- * The details template tag returns a `DetailsToken` object that can print
434
- * itself with the formatted message in two ways.
435
- * It will report full details to the console, but
436
- * mask embedded substitution values with their typeof information in the thrown error
437
- * to prevent revealing secrets up the exceptional path. In the example
438
- * above, the thrown error may reveal only that `sky.color` is a string,
439
- * whereas the same diagnostic printed to the console reveals that the
440
- * sky was green. This masking can be disabled for an individual substitution value
441
- * using `quote`.
442
- *
443
423
  * The `raw` property of an input template array is ignored, so a simple
444
424
  * array of strings may be provided directly.
445
425
  */
@@ -449,70 +429,69 @@ export interface AssertionUtilities {
449
429
  ): DetailsToken;
450
430
 
451
431
  /**
452
- * Use the `Fail` function as a template literal tag to efficiently
453
- * create and throw a `details`-style error only when a condition is not satisfied.
454
- * ```js
455
- * condition || Fail`...complaint...`;
456
- * ```
457
- * This avoids the overhead of creating usually-unnecessary errors like
458
- * ```js
459
- * assert(condition, details`...complaint...`);
460
- * ```
461
- * while improving readability over alternatives like
462
- * ```js
463
- * condition || assert.fail(details`...complaint...`);
464
- * ```
432
+ * Use as a template literal tag to create and throw an error in whose
433
+ * `message` unquoted substitution values (i.e., those that are not output
434
+ * from the {@link quote} function) may have been redacted into lossy `typeof`
435
+ * output but are still available for logging to an associated console.
465
436
  *
466
- * However, due to current weakness in TypeScript, static reasoning
467
- * is less powerful with the `||` patterns than with an `assert` call.
468
- * Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed,
469
- * for `||`-style assertions where this loss of static reasoning is a problem,
470
- * instead express the assertion as
437
+ * For example, using the normal convention to locally rename properties like
438
+ * `const { quote: q, Fail } = assert;`:
471
439
  * ```js
472
- * if (!condition) {
473
- * Fail`...complaint...`;
474
- * }
440
+ * sky.isBlue() || Fail`${sky.color} should be "blue"`;
475
441
  * ```
476
- * or, if needed,
442
+ *
443
+ * This `||` pattern saves the cost of creating {@link DetailsToken} and/or
444
+ * error instances when the asserted condition holds, but can weaken
445
+ * TypeScript static reasoning due to
446
+ * https://github.com/microsoft/TypeScript/issues/51426 . Where this is a
447
+ * problem, instead express the assertion as
477
448
  * ```js
478
- * if (!condition) {
479
- * // `throw` is noop since `Fail` throws, but it improves static analysis
480
- * throw Fail`...complaint...`;
481
- * }
449
+ * if (!sky.isBlue()) {
450
+ * // This `throw` does not affect runtime behavior since `Fail` throws, but
451
+ * // might be needed to improve static analysis.
452
+ * throw Fail`${sky.color} should be "blue"`;
453
+ * }
482
454
  * ```
455
+ *
456
+ * The `raw` property of an input template array is ignored, so a simple
457
+ * array of strings may be provided directly.
483
458
  */
484
459
  Fail(template: TemplateStringsArray | string[], ...args: any): never;
485
460
 
486
461
  /**
487
- * To "declassify" and quote a substitution value used in a
488
- * ``` details`...` ``` template literal, enclose that substitution expression
489
- * in a call to `quote`. This makes the value appear quoted
490
- * (as if with `JSON.stringify`) in the message of the thrown error. The
491
- * payload itself is still passed unquoted to the console as it would be
492
- * without `quote`.
462
+ * Wrap a value such that its use as a substitution value in a template
463
+ * literal tagged with {@link details} or {@link Fail} will result in it
464
+ * appearing quoted (in a way similar to but more general than
465
+ * `JSON.stringify`) rather than redacted in the `message` of errors based on
466
+ * the resulting {@link DetailsToken}.
493
467
  *
494
- * For example, the following will reveal the expected sky color, but not the
495
- * actual incorrect sky color, in the thrown error's message:
496
- * ```js
497
- * sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
498
- * ```
468
+ * This does not affect representation in output of an associated console,
469
+ * which still logs the value as it would without `quote`, but *does* reveal
470
+ * it to functions in the propagation path of such errors.
499
471
  *
500
- * The normal convention is to locally rename `details` to `X` and `quote` to `q`
501
- * like `const { details: X, quote: q } = assert;`, so the above example would then be
472
+ * For example, the following will reveal the expected value in the thrown
473
+ * error's `message`, but only the _type_ of the actual incorrect value (using
474
+ * the normal convention to locally rename properties like
475
+ * `const { quote: q, Fail } = assert;`):
502
476
  * ```js
503
- * sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
477
+ * actual === expected || Fail`${actual} should be ${q(expected)}`;
504
478
  * ```
479
+ *
480
+ * The optional `space` parameter matches that of `JSON.stringify`, and is
481
+ * used to request insertion of non-semantic line feeds, indentation, and
482
+ * separating spaces in the output for improving readability of objects and
483
+ * arrays.
505
484
  */
506
- quote(
507
- /** What to declassify */
508
- payload: any,
509
- spaces?: string | number,
510
- ): /** The declassified and quoted payload */ StringablePayload;
485
+ quote(value: any, space?: string | number): Stringable;
511
486
 
512
487
  /**
513
- * Embed a string directly into error details without wrapping punctuation.
488
+ * Wrap a string such that its use as a substitution value in a template
489
+ * literal tagged with {@link details} or {@link Fail} will be treated
490
+ * literally rather than being quoted or redacted.
491
+ *
514
492
  * To avoid injection attacks that exploit quoting confusion, this must NEVER
515
493
  * be used with data that is possibly attacker-controlled.
494
+ *
516
495
  * As a further safeguard, we fall back to quoting any input that is not a
517
496
  * string of sufficiently word-like parts separated by isolated spaces (rather
518
497
  * than throwing an exception, which could hide the original problem for which
@@ -522,35 +501,25 @@ export interface AssertionUtilities {
522
501
  * by inline replacement similar to that of `bestEffortStringify` for producing
523
502
  * rendered messages like `(an object) was tagged "[Unsafe bare string]"`).
524
503
  */
525
- bare(
526
- /** What to declassify */
527
- payload: any,
528
- spaces?: string | number,
529
- ): /** The declassified payload without quotes (beware confusion hazard) */
530
- StringablePayload;
504
+ bare(text: string, spaces?: string | number): Stringable;
531
505
  }
532
506
 
533
507
  export interface DeprecatedAssertionUtilities {
534
508
  makeAssert: MakeAssert;
509
+ error: AssertionUtilities['makeError'];
535
510
  }
536
511
 
537
512
  /**
538
- * assert that expr is truthy, with an optional details to describe
539
- * the assertion. It is a tagged template literal like
540
- * ```js
541
- * assert(expr, details`....`);`
542
- * ```
543
- *
544
- * The literal portions of the template are assumed non-sensitive, as
545
- * are the `typeof` types of the substitution values. These are
546
- * assembled into the thrown error message. The actual contents of the
547
- * substitution values are assumed sensitive, to be revealed to
548
- * the console only. We assume only the virtual platform's owner can read
549
- * what is written to the console, where the owner is in a privileged
550
- * position over computation running on that platform.
513
+ * Assert that `condition` is truthy, with optional details associated with
514
+ * assertion failure (falsy condition).
551
515
  *
552
- * The optional `optDetails` can be a string for backwards compatibility
553
- * with the nodejs assertion library.
516
+ * The literal portions of the template used to make a {@link DetailsToken} are
517
+ * assumed non-sensitive, as are the `typeof` output for substitution values.
518
+ * These are assembled into the error `message`. The actual contents of the
519
+ * substitution values are assumed sensitive and usually redacted, to be
520
+ * revealed only to an associated console. We assume only the virtual platform's
521
+ * owner can read what is written to the console, where the owner is in a
522
+ * privileged position over computation running on that platform.
554
523
  */
555
524
  export type Assert = AssertionFunctions &
556
525
  AssertionUtilities &
@@ -1,99 +0,0 @@
1
- # Logging Errors
2
-
3
- Summary
4
- * Writing defensive programs under SES requires carefully considering what an error reveals to code positioned to catch those errors up the call chain.
5
- * To that end, SES introduces an `assert` global with functions that add to errors annotations that will be hidden from callers. SES also tames the `Error` constructor to hide the `stack` to parent callers when possible (currently: v8, SpiderMonkey, XS).
6
- * SES tames the global `console` and grants it the ability to reveal error annotations and stacks to the actual console.
7
- * Both `assert` and `console` are powerful globals that SES does not implicitly carry into child compartments. When creating a child compartment, add `assert` to the compartment’s globals. Either add `console` too, or add a wrapper that annotates the console with a topic.
8
- * SES hides annotations and stack traces by default. To reveal them, SES uses mechanisms like `process.on("uncaughtException")` in Node.js to catch the error and log it back to the `console` tamed by `lockdown`.
9
-
10
- We refer to the enhanced `console`, installed by default by the ses shim, as the *causal console*, because the annotations it reveals are often used to show causality information. For example, with the [`TRACK_TURNS=enabled`](https://github.com/Agoric/agoric-sdk/blob/master/docs/env.md#track_turns) and [`DEBUG=track-turns`](https://github.com/Agoric/agoric-sdk/blob/master/docs/env.md#debug) environment options set
11
- ```sh
12
- # in bash syntax
13
- export DEBUG=track-turns
14
- export TRACK_TURNS=enabled
15
- ```
16
- the @endo/eventual-send package will use annotations to show where previous `E` operations (either eventual sends or `E.when`) in previous turns *locally in the same vat* caused the turn with the current error. This is sometimes called "deep asynchronous stacks".
17
- * In the scope of the Agoric software ecosystem, this architecture will allow us to eventually introduce a more powerful distributed causal `console` that can meaningfully capture stack traces for a distributed debugger, based on the design of [Causeway](https://github.com/Agoric/agoric-sdk/issues/1318#issuecomment-662127549).
18
-
19
-
20
- ## Goals, non-goals, and partial goals
21
-
22
- Aside from IDE-based debuggers, the normal JavaScript developer debugging experience rests on the interplay of three widespread building blocks:
23
- * Thrown errors which carry stack traces and explanatory messages.
24
- * An `assert` convenience library for turning violated conditions into diagnostic errors.
25
- * A built-in `console` for producing diagnostic logging information for the developer to look at, or even, in the browser, interact with.
26
-
27
- We are building a distributed secure JavaScript system running on both blockchain and non-chain platforms. Blockchains require determinism, so all validators reproduce the same computation. Despite these constraints&mdash;secure, distributed, deterministic&mdash;we wish to provide the JavaScript developer with a debugging experience at least on par with their current `console` based expectations, and as familiar as possible, so they can hit the ground running.
28
-
29
- The logging systems described at [survey of logging frameworks - Issue #1318](https://github.com/Agoric/agoric-sdk/issues/1318) mostly have very different goals: to produce symbolic records to be post-processed into useful diagnostic information. We still need such a logging system in addition to the system described here. The `console` directly produces information for the developer to look at and possibly interact with. Producing this experience severely constrains the additional symbolic information we can include to aid post-processing, if this additional information would add distracting visual noise.
30
-
31
- ## Configuration variations
32
-
33
- This directory is a system of three related abstractions:
34
- * `Error` Errors carry hidden diagnostic information.
35
- * `assert` Assertions cause and annotate errors.
36
- * `console` Consoles show an enhanced view of logged errors.
37
-
38
- This system must behave well in a variety of configurations:
39
- * After `lockdown` is imported but before repairs.
40
- * `assert` added to global scope of start compartment.
41
- * After repair or `lockdown()` in the start compartment
42
- * All combinations of relevant `lockdown` taming options (`errorTaming` and `consoleTaming`).
43
- * In *created compartments*, i.e., non-start compartments created after `lockdown()`. In our recommended practice, typically
44
- * All created compartments implicitly share the same safe `Error` constructor.
45
- * All compartments explicitly share the same `assert`.
46
- * Each compartment explicitly has its own `filteringConsole` in a tree, enabling filtering by compartment (topic-like) and severity level (`debug`, `log`, `info`, `warn`, and `error`).
47
-
48
- Of these configurations, we are primarily concerned with the post-lockdown, default-safe-taming options, created compartment, recommended endowment pattern. This one must have strong simple security and determinism properties. Variations must differ in understandable ways.
49
-
50
- ## Hiding and Revealing Local Diagnostic Information
51
-
52
- A pervasive concern is hiding diagnostic information&mdash;both for confidentiality and for deterministic replay. Code that obtains access to an error object, for example by catching it, should not have access this hidden diagnostic information. However, the console system produces logging output, typically for human developers to look at to help track down problems. The `console` interface should ideally be a write-only interface when considered by itself. We consider the viewer of log information produced by the console the way we consider the operator of a debug interface of an IDE. We view both as at a meta-level outside the computational system producing the diagnostic information. This system has several categories of hidden diagnostic information:
53
- * **Error stacks**. JavaScript errors capture the callstack at the time an error was created. In normal unsafe JavaScript this is available from error objects themselves via `error.stack`. This general availability violates caller encapsulation, threatening security. The contents of these callstacks are unspecified, non-deterministic, and differ from engine to engine, threatening determinism.
54
- * **Detailed error message data**. JavaScript errors carry a `message` string determined when the error is created, and used to convey further diagnostic information to human developers. However, data dependent values that a human developer may find useful may also reveal information that should not be accessible to code from the error object. Our `assert` provides a `details` template literal tag for creating informative error messages made visible on the logging output, but partially censored in the `message` string carried by error objects.
55
- * **Error annotations**. An error can indicate problems at multiple levels of abstraction. An error thrown by low level code may be diagnostic of a problem explained in low level concepts. A higher level caller may wish to add an explanation in terms of its own higher level concepts. However, if it mearly catches the low level error and then throws a high level error, the low level information is lost. Instead, the catch clause can annotate the low level error with high level diagnostic information and then rethrow the low level error.
56
-
57
- All the above forms of diagnostic information&mdash;error stacks, detailed error messages data, error annotations&mdash;are kept in side tables, hidden from normal code, but used by the console system to display a more informative error log. All these tables are per-realm rather than per-compartment, so an error thrown by code in compartment A, annotated by code in compartment B, and logged by code in compartment C will be displayed or not only according to the compartment C console's filters. The compartment of origin of the other information is irrelevant. In support of this, there is normally only one global safe `Error` constructor shared by all created compartments, one global `assert` shared by all compartments, and one *root* console, which is the console of the start compartment. The `Error` constructor system shares the stack trace side table with the root console. The `assert` shares the detailed message data and annotation side tables with the root console.
58
-
59
- To minimize visual noise, none of the following directly produces any logging output: throwing errors, assertion failure, or error annotation. They record information silently, only to be displayed if reached from an explicit `console` logging action. These logging actions are the root of a graph of this additional accumulated information. The logging action arguments include errors. These errors have both a detailed message that include errors, and detailed message annotations that include errors. Those errors likewise... The console logs this extra information once, with a unique tag per error. Any further occurrences of that error output that unique tag, from which to look up such previous log output.
60
-
61
- Before repair or `lockdown`, we assume there is some prior "system" console bound to the global `console` in the start compartment. `{ consoleTaming: 'unsafe' }` leaves this unsafe system console in place. This system console is completely ignorant of the extra information in these side tables, which is therefore never seen. This includes the hidden data in the detailed messages. Instead, the system console shows the abbreviated `message` text produced by the `details` template literal that omits censored data. When combined with the default `{ errorTaming: 'safe' }`, the system console may not see error stack information. The `{ errorTaming: 'unsafe' }` or `{ errorTaming: 'unsafe-details' }` setting does not remove error stacks from error objects, in which case the system console will find it as usual.
62
-
63
- The default `{ consoleTaming: 'safe' }` setting replaces the system console with a root console that does use all these side tables to generate a more informative log. This root console wraps the prior system console. This root console outputs its log information only by invoking this wrapped system console, which therefore determines how this log information is made available to the external world. To support determinism, we will also need to support a no-op console setting, as explained at [deterministic handling of adversarial code calling console.log with a Proxy #1852](https://github.com/Agoric/agoric-sdk/issues/1852) and [Need no-op console setting for determinism #487](https://github.com/Agoric/SES-shim/issues/487).
64
-
65
- SES considers both `assert` and `console` to be powerful objects, appearing initially in the start compartment, and not permitted for implicit propagation to created compartments. Rather, we recommend an endowment pattern where the global `assert` is passed forward as-is, but only filtered forms of the `console` are. As compartments create each other in a tree, they create a corresponding filtering tree of consoles. Information sent to any compartment's console is then sent up the filtering tree. Only information that survives all the filters in its path arrive at the root console, producing log output. The others have no effect. Given the expected pattern of a compartment per package, the per-compartment console filter is effectly a topic filter, treating the package identity as a topic. We plan to also support coordinated stack-frame filters, as explained at [Need source-prefix-based stackframe filter #488](https://github.com/Agoric/SES-shim/issues/488).
66
-
67
- For security and determinism, we normally reason from the *in-band frame of reference* where the console logging output does not exist, is not an effect, and `console` operations are write-only. Within this frame of reference, the `assert` and `console` powers are not very powerful. They are almost as safe as the permitted, powerless, shared primordials, which is why we're willing to recommend this endowment pattern be habitual.
68
-
69
- ## Hiding and Revealing Distributed Diagnostic Information
70
-
71
- This section explains our *plans* to build a distributed logging experience on top of this system. Also tracked at [Support stack-tracking serialization of error objects #1863](https://github.com/Agoric/agoric-sdk/issues/1863).
72
-
73
- Only a local system will have a meaningful notion of "the developer" that should see all hidden diagnostic information. Our overall system is a decentralized fabric of multiple mutually suspicious platforms, including both public and private chains, and public and private non-chains. Alice running private chain A may or may not be willing to release A's logs to Bob, running public chain B, even if it would help Bob diagnose a problem. Our system must support Bob in both scenarios. When Bob can get all the relevant logs, we wish his debugging experience to approximate as close as possible the pleasure of the local debugging experience. When Bob can only get some logs, his ability to debug should degrade gracefully.
74
-
75
- Our comm system sends errors by copy. At the level of abstraction of the distributed computation, an error serialized and sent by Alice is the "same" as the error as received and unserialized by Bob. At the JavaScript level of abstraction, they are of course distinct objects. Alice's system holds all this extra hidden information about the error she's sending, that her console uses to output useful diagnostic information. Alice's comm system therefore cannot simply serialize and send this information to untrusted Bob. Instead, Alice's comm system should generate identifying information which allegedly identifies this error. Alice's comm system should include this identifier in the serialization of the error, and it should arrange to locally log the association of this error with this identifier. Bob's comm system, on unserializing the error, should annotate this new error with this identifying information from the unserialization of this error.
76
-
77
- If Bob's computation then causes that error to be logged, its local stack trace will uselessly identify the unserialializer as the code that created the error. But the annotation should inform Bob that he should go ask Alice for the logs containing the identified error. With more tooling to make such arrangements more automatic and immediate, the relevant portions of Alice's log could be made to appear to Bob as-if they are available in his own local diagnostic information.
78
-
79
- However, the above description violates one of our constraints: The automatic logging of a sent error to Alice's log is noisy, especially if neither that error nor its remote copy would ever otherwise be logged. Ideally, this would instead be handled by that [other kind of logging system](https://github.com/Agoric/agoric-sdk/issues/1318) that produces symbolic output to be post-processed into useful diagnostic information. However, this particular special case is uniquely urgent and might not wait for us to build that other kind of logging system. As one possible mechanism, the comm system could maintain a bounded in-memory table of sent errors. If Bob's request arrive while the identified error is still in Alice's table, and Alice wishes to reveal this info to Bob, Alice can log it then.
80
-
81
- ## Hiding and Revealing Asynchronous Diagnostic Information
82
-
83
- This section explains our *plans* to build a logging experience on top of this system that supports local and distributed asynchrony. Also tracked at [Support deep stacks for local asynchronous log-based debugging #1862](https://github.com/Agoric/agoric-sdk/issues/1862) and [Support distributed deep stacks for log-based debugging #1864](https://github.com/Agoric/agoric-sdk/issues/1864).
84
-
85
- JavaScript itself is not a dustributed language, but it is a highly asynchronous language. Our distributed computational model&mdash;communicating event loops&mdash;pushes much of our code into making heavy use of this asynchrony. For such code, individual synchronous call stacks are often short and uninformative. [Causeway](https://github.com/Agoric/agoric-sdk/issues/1318#issuecomment-662127549) shows that the asynchronous and distributed analog of synchronous stack traces is a directed acyclic graph of prior causal events, each with their local synchronous stack at their moment of causation. To capture this well requires instrumenting the promise system in ways impossible for user code. However, the most important causal paths are
86
- * the [eventual-send](https://github.com/tc39/proposal-eventual-send) operations by [handled promise](../../../eventual-send/README.md), whether expressed by `E()` or `~.`.
87
- * the `.then` operation. However, we replace the builtin `Promise.prototype.then` at our peril. Many built in operations implicitly invoke the original binding of `Promise.prototype.then` in ways we cannot override. However, our same eventual-send package already provides a safer alternative `E.when` operation.
88
-
89
- Restricting the instrumentation to these two operations gives predictability and preserves platform independence, but at the loss of some useful diagnostic information. This loss may encourage programmers to shift from their current habits to eventual-send and `E.when`, which would be a good thing anyway.
90
-
91
- (Note that some IDE debug experiences now include deep stacks over `await` boundaries. However, the engine provides to access to this mechanism from JavaScript. Without it, these stacks are impossible to capture without an invasive code transform.)
92
-
93
- Ideally, the diagnostic information produced by such instrumentation should be sent to [other kind of logging system](https://github.com/Agoric/agoric-sdk/issues/1318), for post-processing by other tools. But it is at least possible to encode it in the system described here. The instrumentation would add enough overhead to eventual-send and `E.when` that it should not be the default setting. When the instrumentation is on, each `E()` or `E.when` operation would create a hidden error, to be associated with the turn it causes. When that turn does such an action, the hidden error it similarly creates would be annotated with the hidden error from the action that created this turn. Looking forward, this records a causal tree of events. Looking backward, it creates a linear "deep stack" of events&mdash;a sequence of shallow stacks. All this extra bookkeeping remains silent until an error is logged. Once an error is logged, its deep stack is included in the recursive logging of its annotations.
94
-
95
- (However, this pattern of use will accumulate deep annotation trees&mdash;too deep to keep in memory. Instead we would need to bound the number of annotations we remember, which would require a different data structure.)
96
-
97
- ## Unreal logging
98
-
99
- For deterministically replayable computation, we could support the full debugging experience even if the "real" computation never logs anything. Such a no-op logging system would not need any side tables, and so has no problem with side table memory pressure. Such a no-op logging system never examines logged objects, and so does not create a communications channel. Instead, all logging only happens offline, under instrumented deterministic replay, and only for computation containing a mystery to be diagnosed. Under this scenario, even expensive instrumentation may be very affordable. Under this scenario, if Alice gives Bob enough information to deterministically replay the relevant chain A computation, she's effectively given Bob all the logging information he could ever want. Under this scenario, no mechanism is needed to exempt logging output for on-chain determinism rules, since there would be no on-chain logging output.