Skip to content

API documentation of Agoric SDK / Exports / @agoric/assert / assert

Module: assert

Table of contents

References

Functions

References

q

Renames and re-exports quote

Functions

Fail

Fail(template, ...args): never

Parameters

NameType
templateTemplateStringsArray | string[]
...argsany

Returns

never

Defined in

assert.js:55


NonNullish

NonNullish<T>(val, optDetails?): T

Type parameters

Name
T

Parameters

NameType
valundefined | null | T
optDetails?string

Returns

T

Defined in

assert.js:65


an

an(str): string

Prepend the correct indefinite article onto a noun, typically a typeof result e.g., "an Object" vs. "a Number"

Parameters

NameTypeDescription
strstringThe noun to prepend

Returns

string

The noun prepended with a/an

Deprecated

Defined in

assert.js:82


assert

assert(flag, optDetails?, ErrorConstructor?): asserts flag

Parameters

NameTypeDescription
flaganyThe truthy/falsy value
optDetails?DetailsThe details to throw
ErrorConstructor?ErrorConstructorAn optional alternate error constructor to use.

Returns

asserts flag

Defined in

assert.js:28


details

details(template, ...args): DetailsToken

Parameters

NameType
templateTemplateStringsArray | string[]
...argsany

Returns

DetailsToken

Defined in

assert.js:55


makeAssert

makeAssert(optRaise?, unredacted?): Assert

Parameters

NameType
optRaise?Raise
unredacted?boolean

Returns

Assert

Defined in

assert.js:55


quote

quote(payload, spaces?): StringablePayload

To "declassify" and quote a substitution value used in a details`...` template literal, enclose that substitution expression in a call to quote. This makes the value appear quoted (as if with JSON.stringify) in the message of the thrown error. The payload itself is still passed unquoted to the console as it would be without quote.

Parameters

NameTypeDescription
payloadanyWhat to declassify
spaces?string | number-

Returns

StringablePayload

The declassified payload

Example

For example, the following will reveal the expected sky color, but not the actual incorrect sky color, in the thrown error's message:

js
sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;

Example

The normal convention is to locally rename details to X and quote to q like const { details: X, quote: q } = assert;, so the above example would then be

js
sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;

Defined in

assert.js:55