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
| Name | Type |
|---|---|
template | TemplateStringsArray | string[] |
...args | any |
Returns
never
Defined in
NonNullish
▸ NonNullish<T>(val, optDetails?): T
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
val | undefined | null | T |
optDetails? | string |
Returns
T
Defined in
an
▸ an(str): string
Prepend the correct indefinite article onto a noun, typically a typeof result e.g., "an Object" vs. "a Number"
Parameters
| Name | Type | Description |
|---|---|---|
str | string | The noun to prepend |
Returns
string
The noun prepended with a/an
Deprecated
Defined in
assert
▸ assert(flag, optDetails?, ErrorConstructor?): asserts flag
Parameters
| Name | Type | Description |
|---|---|---|
flag | any | The truthy/falsy value |
optDetails? | Details | The details to throw |
ErrorConstructor? | ErrorConstructor | An optional alternate error constructor to use. |
Returns
asserts flag
Defined in
details
▸ details(template, ...args): DetailsToken
Parameters
| Name | Type |
|---|---|
template | TemplateStringsArray | string[] |
...args | any |
Returns
Defined in
makeAssert
▸ makeAssert(optRaise?, unredacted?): Assert
Parameters
| Name | Type |
|---|---|
optRaise? | Raise |
unredacted? | boolean |
Returns
Defined in
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
| Name | Type | Description |
|---|---|---|
payload | any | What to declassify |
spaces? | string | number | - |
Returns
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:
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
sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;