Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion doc/api/assert.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Assert

<!--introduced_in=v0.10.0-->
<!--introduced_in=v0.1.21-->

> Stability: 2 - Stable

Expand All @@ -13,6 +13,71 @@ A `strict` and a `legacy` mode exist, while it is recommended to only use
For more information about the used equality comparisons see
[MDN's guide on equality comparisons and sameness][mdn-equality-guide].

## Class: AssertionError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is not global, should not this be ## Class: assert.AssertionError?

Compare:
Class: net.Server and Class: net.Socket


A subclass of `Error` that indicates the failure of an assertion.
All errors thrown by the assert module will be instance of the `AssertionError`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but maybe instance -> instances?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert module -> `assert` module (add backticks)

class.

### new AssertionError(options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same.
Compare: new net.Server() and new net.Socket().

<!-- YAML
added: v0.1.21
-->
* `options` {Object}
* `message` {string} If provided, the error message is going to be set to this
value.
* `actual` {any} The `actual` property on the error instance is going to
contain this value. Internally used for the `actual` error input in case
e.g., [`assert.strictEqual()`] is used.
* `expected` {any} The `expected` property on the error instance is going to
contain this value. Internally used for the `expected` error input in case
e.g., [`assert.strictEqual()`] is used.
* `operator` {string} The `operator` property on the error instance is going
to contain this value. Internally used to indicate what operation was used
for comparison (or what assertion function triggered the error).
* `stackStartFn` {Function} If provided, the generated stack trace is going to
remove all frames up to the provided function.

A subclass of `Error` that indicates the failure of an assertion.

All instances contain the built-in Error properties (i.e., `message` and `name`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add backticks around Error.
  • Is i.e. the right abbreviation here? If so, then just get rid of i.e.. If not, change it to including or such as.

plus the following:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus the following: -> and:


* `actual` {any} Set to the actual value in case e.g.,
[`assert.strictEqual()`] is used.
* `expected` {any} Set to the expected value in case e.g.,
[`assert.strictEqual()`] is used.
* `generatedMessage` {boolean} Indicates if the message was auto generated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but maybe auto generated -> auto-generated?

(`true`) or not.
* `code` {string} This is always set to the string `ERR_ASSERTION` to indicate
that the error is actually a assertion error.
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a assertion -> an assertion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a assertion -> an assertion?

* `operator` {string} Set to the passed in operator value.

```js
const assert = require('assert');

// Generate a AssertionError to compare the error message later:.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a AssertionError -> an AssertionError?

:. -> :?

const { message } = new assert.AssertionError({
actual: 1,
expected: 2,
operator: '=='
});

// Verify error output:
try {
assert.equal(1, 2);
} catch (err) {
assert(err instanceof assert.AssertionError);
assert.equal(err.message, message);
assert.equal(err.name, 'AssertionError [ERR_ASSERTION]');
assert.equal(err.actual, 1);
assert.equal(err.expected, 2);
assert.equal(err.code, 'ERR_ASSERTION');
assert.equal(err.operator, '==');
assert.equal(err.generatedMessage, true);
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should popularize legacy loose equality mode here.
Mabe this way?

const assert = require('assert');

// Generate an AssertionError to compare the error message later:
const { message } = new assert.AssertionError({
  actual: 1,
  expected: 2,
  operator: 'strictEqual'
});

// Verify error output:
try {
  assert.strictEqual(1, 2);
} catch (err) {
  assert(err instanceof assert.AssertionError);
  assert.strictEqual(err.message, message);
  assert.strictEqual(err.name, 'AssertionError [ERR_ASSERTION]');
  assert.strictEqual(err.actual, 1);
  assert.strictEqual(err.expected, 2);
  assert.strictEqual(err.code, 'ERR_ASSERTION');
  assert.strictEqual(err.operator, 'strictEqual');
  assert.strictEqual(err.generatedMessage, true);
}

Or maybe with 1 and '1'?

}
```

## Strict mode
<!-- YAML
added: v9.9.0
Expand Down
10 changes: 3 additions & 7 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,8 @@ detailed [here](#errors_system_errors).

## Class: AssertionError

A subclass of `Error` that indicates the failure of an assertion. Such errors
commonly indicate inequality of actual and expected value.

```js
assert.strictEqual(1, 2);
// AssertionError [ERR_ASSERTION]: 1 === 2
```
A subclass of `Error` that indicates the failure of an assertion. For further
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microscopic nit that can totally be ignored if you want: The word further can be omitted. For that matter, so can all of For further details,. It can just be See [`Class: AssertionError`][].

details check asserts [`Class: AssertionError`][].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asserts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comma after details and change check to see.


## Class: RangeError

Expand Down Expand Up @@ -1680,6 +1675,7 @@ Creation of a [`zlib`][] object failed due to incorrect configuration.
[`process.setUncaughtExceptionCaptureCallback()`]: process.html#process_process_setuncaughtexceptioncapturecallback_fn
[`require('crypto').setEngine()`]: crypto.html#crypto_crypto_setengine_engine_flags
[`server.listen()`]: net.html#net_server_listen
[`Class: AssertionError`]: assert.html#class_assertionerror
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

##assert_class_assertionerror?

Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, if the suggestions given below are valid, even #assert_class_assert_assertionerror.

[ES6 module]: esm.html
[Node.js Error Codes]: #nodejs-error-codes
[V8's stack trace API]: https://github.com/v8/v8/wiki/Stack-Trace-API
Expand Down