Skip to content

Commit

Permalink
Remove usages of assert in all code that ends up bundled in the brows…
Browse files Browse the repository at this point in the history
…er (#4144)

* V1 plugin

* Better version of the plugin

* Revert package.lock.json

* Update a bunch of asserts

* More assert removals

* More client side packages

* More assert conversions

* Last set of conversions

* Update webpack plugin

* Undo lockfile changes

* More updates

* It compiles!

* Package-lock bump

* Remove some asserts, add error message

* Newer version of banned modules plugin

* Typescript output

* Clean up some build issues

* Erroneous assert

* Undo lockfile

* Fix tests that assumed assert errors
  • Loading branch information
christiango authored Oct 29, 2020
1 parent cee4f27 commit 61bd2cc
Show file tree
Hide file tree
Showing 97 changed files with 233 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import * as api from "@fluid-internal/client-api";
import * as ink from "@fluidframework/ink";
import { assert } from "@fluidframework/common-utils";
import * as ui from "../ui";
import { getShapes } from "./canvasCommon";
import * as recognizer from "./shapeRecognizer";
Expand Down Expand Up @@ -81,7 +81,7 @@ export class DrawingContext {
// Store instructions used to render itself? i.e. the total path? Or defer to someone else to actually
// do the re-render with a context?
public drawSegmentToNewPoint(endPoint: ink.IInkPoint) {
assert(this.pen);
assert(!!this.pen);

const previous = this.lastPoint || endPoint;
const shapes = getShapes(previous, endPoint, this.pen, SegmentCircleInclusive.End);
Expand Down
1 change: 1 addition & 0 deletions examples/data-objects/key-value-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"@fluidframework/aqueduct": "^0.28.0",
"@fluidframework/common-utils": "^0.25.0-0",
"@fluidframework/container-definitions": "^0.28.0",
"@fluidframework/container-runtime": "^0.28.0",
"@fluidframework/core-interfaces": "^0.28.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/data-objects/key-value-cache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import {
IFluidObject,
IFluidRouter,
Expand Down Expand Up @@ -31,6 +30,7 @@ import {
buildRuntimeRequestHandler,
} from "@fluidframework/request-handler";
import { defaultRouteRequestHandler } from "@fluidframework/aqueduct";
import { assert } from "@fluidframework/common-utils";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../package.json");
Expand Down Expand Up @@ -68,7 +68,7 @@ class KeyValue implements IKeyValue, IFluidObject, IFluidRouter {
private _root: ISharedMap | undefined;

public get root() {
assert(this._root);
assert(!!this._root);
return this._root;
}

Expand Down
1 change: 1 addition & 0 deletions examples/data-objects/prosemirror/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"@fluidframework/aqueduct": "^0.28.0",
"@fluidframework/common-utils": "^0.25.0-0",
"@fluidframework/container-definitions": "^0.28.0",
"@fluidframework/container-runtime": "^0.28.0",
"@fluidframework/core-interfaces": "^0.28.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/prosemirror/src/fluidBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import {
createInsertSegmentOp,
Marker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { EventEmitter } from "events";
import { assert } from "@fluidframework/common-utils";
import { ILoader } from "@fluidframework/container-definitions";
import {
createGroupOp,
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/shared-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// eslint-disable-next-line import/no-unassigned-import
import "./publicpath";

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { IContainerContext, IRuntime, IRuntimeFactory } from "@fluidframework/container-definitions";
import { ContainerRuntime } from "@fluidframework/container-runtime";
import {
Expand Down
1 change: 1 addition & 0 deletions examples/data-objects/smde/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"@fluidframework/aqueduct": "^0.28.0",
"@fluidframework/common-utils": "^0.25.0-0",
"@fluidframework/container-definitions": "^0.28.0",
"@fluidframework/container-runtime": "^0.28.0",
"@fluidframework/core-interfaces": "^0.28.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/data-objects/smde/src/smde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { EventEmitter } from "events";
import { assert } from "@fluidframework/common-utils";
import {
IFluidObject,
IFluidLoadable,
Expand Down Expand Up @@ -58,7 +58,7 @@ export class Smde extends EventEmitter implements
private smde: SimpleMDE | undefined;

private get text() {
assert(this._text);
assert(!!this._text);
return this._text;
}
constructor(private readonly runtime: IFluidDataStoreRuntime, private readonly context: IFluidDataStoreContext) {
Expand Down
1 change: 1 addition & 0 deletions examples/data-objects/table-document/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"@fluidframework/aqueduct": "^0.28.0",
"@fluidframework/common-definitions": "^0.19.1",
"@fluidframework/common-utils": "^0.25.0-0",
"@fluidframework/core-interfaces": "^0.28.0",
"@fluidframework/datastore-definitions": "^0.28.0",
"@fluidframework/merge-tree": "^0.28.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/data-objects/table-document/src/cellrange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { LocalReference } from "@fluidframework/merge-tree";
import { SequenceInterval } from "@fluidframework/sequence";

Expand Down Expand Up @@ -47,7 +47,7 @@ export class CellRange {
private readonly resolve: (localRef: LocalReference) => { row: number; col: number },
) {
// Ensure CellInterval was not created with a null/undefined interval.
assert(interval);
assert(!!interval);
}

public getRange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { PropertySet } from "@fluidframework/merge-tree";
import { IFluidDataStoreContext } from "@fluidframework/runtime-definitions";
import { ITable, TableDocumentItem } from "../table";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ describe("Table Document with Interception", () => {
try {
tableDocumentWithInterception.setCellValue(cell.row, cell.col, cell.value);
} catch (error) {
assert(error instanceof assert.AssertionError,
assert.strictEqual(error.message,
"Interception wrapper method called recursively from the interception callback",
"We should have caught an assert in setCellValue because it detects an infinite recursion");
asserted = true;
}
Expand Down
1 change: 1 addition & 0 deletions examples/data-objects/webflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"dependencies": {
"@fluid-example/flow-util-lib": "^0.28.0",
"@fluidframework/common-definitions": "^0.19.1",
"@fluidframework/common-utils": "^0.25.0-0",
"@fluidframework/core-interfaces": "^0.28.0",
"@fluidframework/data-object-base": "^0.28.0",
"@fluidframework/map": "^0.28.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/data-objects/webflow/src/document/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { randomId, TokenList, TagName } from "@fluid-example/flow-util-lib";
import { LazyLoadedDataObject, LazyLoadedDataObjectFactory } from "@fluidframework/data-object-base";
import { IFluidHandle } from "@fluidframework/core-interfaces";
Expand Down Expand Up @@ -84,7 +84,7 @@ export const getDocSegmentKind = (segment: ISegment): DocSegmentKind => {

// Ensure that 'nestEnd' range label matches the 'beginTags' range label (otherwise it
// will not close the range.)
assert.equal(segment.getRangeLabels()[0], DocSegmentKind.beginTags, `Unknown refType '${markerType}'.`);
assert(segment.getRangeLabels()[0] === DocSegmentKind.beginTags, `Unknown refType '${markerType}'.`);
return DocSegmentKind.endTags;
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/data-objects/webflow/src/html/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { Caret as CaretUtil, Direction, Rect, TagName } from "@fluid-example/flow-util-lib";
import { IFluidObject } from "@fluidframework/core-interfaces";
import { Marker, TextSegment } from "@fluidframework/merge-tree";
Expand Down Expand Up @@ -56,12 +56,12 @@ class HtmlFormatter extends RootFormatter<IFormatterState> {
case DocSegmentKind.endTags: {
// If the DocumentFormatter encounters an 'endRange', presumably this is because the 'beginTag'
// has not yet been inserted. Ignore it.
assert.strictEqual(layout.doc.getStart(segment as Marker), undefined);
assert(layout.doc.getStart(segment as Marker) === undefined);
return { state, consumed: true };
}

default:
assert.fail(`Unhandled DocSegmentKind '${kind}' @${layout.position}`);
throw new Error(`Unhandled DocSegmentKind '${kind}' @${layout.position}`);
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ export class InclusionFormatter extends Formatter<IInclusionState> {
}

public visit(layout: Layout, state: Readonly<IInclusionState>) {
assert.strictEqual(getDocSegmentKind(layout.segment), DocSegmentKind.inclusion);
assert(getDocSegmentKind(layout.segment) === DocSegmentKind.inclusion);
layout.popFormat();
return { state, consumed: true };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/cell/src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert , fromBase64ToUtf8 } from "@fluidframework/common-utils";
import { ISerializedHandle } from "@fluidframework/core-interfaces";
import { fromBase64ToUtf8 } from "@fluidframework/common-utils";

import {
FileMode,
ISequencedDocumentMessage,
Expand Down
3 changes: 1 addition & 2 deletions packages/dds/map/src/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { fromBase64ToUtf8 } from "@fluidframework/common-utils";
import { assert, fromBase64ToUtf8 } from "@fluidframework/common-utils";
import { addBlobToTree } from "@fluidframework/protocol-base";
import {
ISequencedDocumentMessage,
Expand Down
3 changes: 1 addition & 2 deletions packages/dds/map/src/mapKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { IFluidHandle } from "@fluidframework/core-interfaces";
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
import { makeHandlesSerializable, parseHandles, ValueType } from "@fluidframework/shared-object-base";
import { TypedEventEmitter } from "@fluidframework/common-utils";
import { assert, TypedEventEmitter } from "@fluidframework/common-utils";
import {
ISerializableValue,
ISerializedValue,
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/matrix/src/handlecache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-disable no-bitwise */

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { IVectorConsumer } from "@tiny-calc/nano";
import { Handle, isHandleValid } from "./handletable";
import { PermutationVector, PermutationSegment } from "./permutationvector";
Expand Down
13 changes: 6 additions & 7 deletions packages/dds/matrix/src/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import {
FileMode,
ISequencedDocumentMessage,
Expand Down Expand Up @@ -108,7 +108,7 @@ export class SharedMatrix<T extends Serializable = Serializable>
* Subscribes the given IUndoConsumer to the matrix.
*/
public openUndo(consumer: IUndoConsumer) {
assert.equal(this.undo, undefined,
assert(this.undo === undefined,
"SharedMatrix.openUndo() supports at most a single IUndoConsumer.");

this.undo = new MatrixUndoProvider(consumer, this, this.rows, this.cols);
Expand Down Expand Up @@ -440,7 +440,7 @@ export class SharedMatrix<T extends Serializable = Serializable>
protected submitLocalMessage(message: any, localOpMetadata?: any) {
// TODO: Recommend moving this assertion into SharedObject
// (See https://github.com/microsoft/FluidFramework/issues/2559)
assert.equal(this.isAttached(), true);
assert(this.isAttached() === true);

super.submitLocalMessage(
makeHandlesSerializable(
Expand All @@ -452,9 +452,8 @@ export class SharedMatrix<T extends Serializable = Serializable>
);

// Ensure that row/col 'localSeq' are synchronized (see 'nextLocalSeq()').
assert.equal(
this.rows.getCollabWindow().localSeq,
this.cols.getCollabWindow().localSeq,
assert(
this.rows.getCollabWindow().localSeq === this.cols.getCollabWindow().localSeq,
);
}

Expand All @@ -468,7 +467,7 @@ export class SharedMatrix<T extends Serializable = Serializable>
}

protected onConnect() {
assert.equal(this.rows.getCollabWindow().collaborating, this.cols.getCollabWindow().collaborating);
assert(this.rows.getCollabWindow().collaborating === this.cols.getCollabWindow().collaborating);

// Update merge tree collaboration information with new client ID and then resend pending ops
this.rows.startOrUpdateCollaboration(this.runtime.clientId as string);
Expand Down
6 changes: 3 additions & 3 deletions packages/dds/matrix/src/permutationvector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { ChildLogger } from "@fluidframework/telemetry-utils";
import { IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions";
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
Expand Down Expand Up @@ -54,7 +54,7 @@ export class PermutationSegment extends BaseSegment {

public get start() { return this._start; }
public set start(value: Handle) {
assert.equal(this._start, Handle.unallocated);
assert(this._start === Handle.unallocated);
assert(isHandleValid(value));

this._start = value;
Expand Down Expand Up @@ -346,7 +346,7 @@ export class PermutationVector extends Client {
}

default:
assert.fail();
throw new Error("Unhandled MergeTreeDeltaType");
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/dds/matrix/src/undoprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { assert } from "@fluidframework/common-utils";
import { Serializable } from "@fluidframework/datastore-definitions";
import { TrackingGroup, MergeTreeDeltaOperationType, MergeTreeDeltaType } from "@fluidframework/merge-tree";
import { SharedMatrix } from "./matrix";
Expand Down Expand Up @@ -63,7 +63,7 @@ export class VectorUndoProvider {
}

default:
assert.fail("operation type not revertible");
throw new Error("operation type not revertible");
}

// If we are in the process of reverting, set 'currentOp' to remind ourselves not to push
Expand Down
Loading

0 comments on commit 61bd2cc

Please sign in to comment.