Skip to content

Commit 3905400

Browse files
dannimadanthony-murphy-agent
authored andcommitted
tag asserts (microsoft#25506)
`pnpm run policy-check:asserts`. Fixing some duplicate asserts as well.
1 parent 382c523 commit 3905400

File tree

5 files changed

+54
-37
lines changed

5 files changed

+54
-37
lines changed

packages/dds/task-manager/src/taskManager.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function assertIsTaskManagerOperation(op: unknown): asserts op is ITaskManagerOp
6262
typeof op.taskId === "string" &&
6363
"type" in op &&
6464
(op.type === "volunteer" || op.type === "abandon" || op.type === "complete"),
65-
"Not a TaskManager operation",
65+
0xc3b /* Not a TaskManager operation */,
6666
);
6767
}
6868

@@ -146,11 +146,11 @@ export class TaskManagerClass
146146
(taskId: string, clientId: string, local: boolean, messageId: number | undefined) => {
147147
if (local) {
148148
const latestPendingOps = this.latestPendingOps.get(taskId);
149-
assert(latestPendingOps !== undefined, "No pending ops for task");
149+
assert(latestPendingOps !== undefined, 0xc3c /* No pending ops for task */);
150150
const pendingOp = latestPendingOps.shift();
151151
assert(
152152
pendingOp !== undefined && pendingOp.messageId === messageId,
153-
"Unexpected op",
153+
0xc3d /* Unexpected op */,
154154
);
155155
assert(pendingOp.type === "volunteer", 0x07c /* "Unexpected op type" */);
156156
if (latestPendingOps.length === 0) {
@@ -167,11 +167,11 @@ export class TaskManagerClass
167167
(taskId: string, clientId: string, local: boolean, messageId: number | undefined) => {
168168
if (local) {
169169
const latestPendingOps = this.latestPendingOps.get(taskId);
170-
assert(latestPendingOps !== undefined, "No pending ops for task");
170+
assert(latestPendingOps !== undefined, 0xc3e /* No pending ops for task */);
171171
const pendingOp = latestPendingOps.shift();
172172
assert(
173173
pendingOp !== undefined && pendingOp.messageId === messageId,
174-
"Unexpected op",
174+
0xc3f /* Unexpected op */,
175175
);
176176
assert(pendingOp.type === "abandon", 0x07e /* "Unexpected op type" */);
177177
if (latestPendingOps.length === 0) {
@@ -189,11 +189,11 @@ export class TaskManagerClass
189189
(taskId: string, clientId: string, local: boolean, messageId: number | undefined) => {
190190
if (local) {
191191
const latestPendingOps = this.latestPendingOps.get(taskId);
192-
assert(latestPendingOps !== undefined, "No pending ops for task");
192+
assert(latestPendingOps !== undefined, 0xc40 /* No pending ops for task */);
193193
const pendingOp = latestPendingOps.shift();
194194
assert(
195195
pendingOp !== undefined && pendingOp.messageId === messageId,
196-
"Unexpected op",
196+
0xc41 /* Unexpected op */,
197197
);
198198
assert(pendingOp.type === "complete", 0x401 /* Unexpected op type */);
199199
if (latestPendingOps.length === 0) {
@@ -682,11 +682,11 @@ export class TaskManagerClass
682682
protected reSubmitCore(content: unknown, localOpMetadata: number): void {
683683
assertIsTaskManagerOperation(content);
684684
const pendingOps = this.latestPendingOps.get(content.taskId);
685-
assert(pendingOps !== undefined, "No pending ops for task on resubmit attempt");
685+
assert(pendingOps !== undefined, 0xc42 /* No pending ops for task on resubmit attempt */);
686686
const pendingOpIndex = pendingOps.findIndex(
687687
(op) => op.messageId === localOpMetadata && op.type === content.type,
688688
);
689-
assert(pendingOpIndex !== -1, "Could not match pending op on resubmit attempt");
689+
assert(pendingOpIndex !== -1, 0xc43 /* Could not match pending op on resubmit attempt */);
690690
pendingOps.splice(pendingOpIndex, 1);
691691
if (pendingOps.length === 0) {
692692
this.latestPendingOps.delete(content.taskId);
@@ -841,7 +841,7 @@ export class TaskManagerClass
841841
return false;
842842
}
843843

844-
assert(this.clientId !== undefined, 0x07f /* "clientId undefined" */);
844+
assert(this.clientId !== undefined, 0xc44 /* clientId undefined */);
845845

846846
const inQueue = this.taskQueues.get(taskId)?.includes(this.clientId) ?? false;
847847
const latestPendingOps = this.latestPendingOps.get(taskId);
@@ -879,14 +879,17 @@ export class TaskManagerClass
879879
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.rollback}
880880
*/
881881
protected rollback(content: unknown, localOpMetadata: unknown): void {
882-
assert(typeof localOpMetadata === "number", "Expect localOpMetadata to be a number");
882+
assert(
883+
typeof localOpMetadata === "number",
884+
0xc45 /* Expect localOpMetadata to be a number */,
885+
);
883886
assertIsTaskManagerOperation(content);
884887
const latestPendingOps = this.latestPendingOps.get(content.taskId);
885-
assert(latestPendingOps !== undefined, "No pending ops when trying to rollback");
888+
assert(latestPendingOps !== undefined, 0xc46 /* No pending ops when trying to rollback */);
886889
const pendingOpToRollback = latestPendingOps.pop();
887890
assert(
888891
pendingOpToRollback !== undefined && pendingOpToRollback.messageId === localOpMetadata,
889-
"pending op mismatch",
892+
0xc47 /* pending op mismatch */,
890893
);
891894
if (latestPendingOps.length === 0) {
892895
this.latestPendingOps.delete(content.taskId);

packages/dds/tree/src/simple-tree/api/dirtyIndex.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
7373

7474
return createAnnouncedVisitor({
7575
beforeDetach: (src) => {
76-
assert(parent !== undefined, "Expected node");
77-
assert(parentField !== undefined, "Expected field");
76+
assert(parent !== undefined, 0xc48 /* Expected node */);
77+
assert(parentField !== undefined, 0xc49 /* Expected field */);
7878
for (let parentIndex = src.start; parentIndex < src.end; parentIndex++) {
7979
const path: UpPath = {
8080
parent,
@@ -95,8 +95,8 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
9595
}
9696
},
9797
afterAttach: (_, dst) => {
98-
assert(parent !== undefined, "Expected node");
99-
assert(parentField !== undefined, "Expected field");
98+
assert(parent !== undefined, 0xc4a /* Expected node */);
99+
assert(parentField !== undefined, 0xc4b /* Expected field */);
100100
for (let parentIndex = dst.start; parentIndex < dst.end; parentIndex++) {
101101
const path: UpPath = {
102102
parent,
@@ -116,7 +116,7 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
116116
}
117117
},
118118
enterNode(index: number): void {
119-
assert(parentField !== undefined, "Expected field");
119+
assert(parentField !== undefined, 0xc4c /* Expected field */);
120120
parent = {
121121
parent,
122122
parentField,
@@ -125,7 +125,7 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
125125
parentField = undefined;
126126
},
127127
exitNode(): void {
128-
assert(parent !== undefined, "Expected node");
128+
assert(parent !== undefined, 0xc4d /* Expected node */);
129129
parentField = parent.parentField;
130130
parent = parent.parent;
131131
},
@@ -141,7 +141,7 @@ function createDirtyVisitor(forest: IEditableForest, dirty: DirtyTreeMap): Annou
141141
function getNodeAtPath(forest: IEditableForest, path: UpPath): TreeNode | undefined {
142142
const cursor = forest.allocateCursor();
143143
forest.moveCursorToPath(path, cursor);
144-
assert(cursor.mode === CursorLocationType.Nodes, 0xa9c /* attach should happen in a node */);
144+
assert(cursor.mode === CursorLocationType.Nodes, 0xc4e /* attach should happen in a node */);
145145
const anchor = cursor.buildAnchor();
146146
const anchorNode = forest.anchors.locate(anchor);
147147
cursor.free();

packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
448448
if (!this.#events.hasListeners(eventName)) {
449449
assert(
450450
!this.#disposeSourceListeners.has(eventName),
451-
"Should not have a dispose function without listeners",
451+
0xc4f /* Should not have a dispose function without listeners */,
452452
);
453453

454454
const off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));
@@ -479,7 +479,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
479479
this.#assertNotDisposed();
480480
switch (eventName) {
481481
case "childrenChangedAfterBatch":
482-
assert(arg !== undefined, "childrenChangedAfterBatch should have arg");
482+
assert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);
483483
return this.#handleChildrenChangedAfterBatch(arg.changedFields);
484484
case "subtreeChangedAfterBatch":
485485
return this.#handleSubtreeChangedAfterBatch();
@@ -526,7 +526,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
526526
}
527527

528528
#assertNotDisposed(): void {
529-
assert(!this.#disposed, "Event handler disposed.");
529+
assert(!this.#disposed, 0xc51 /* Event handler disposed. */);
530530
}
531531

532532
public dispose(): void {
@@ -536,7 +536,7 @@ class KernelEventBuffer implements Listenable<KernelEvents> {
536536

537537
assert(
538538
this.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,
539-
"Buffered kernel events should have been flushed before disposing.",
539+
0xc52 /* Buffered kernel events should have been flushed before disposing. */,
540540
);
541541

542542
this.#disposeOnFlushListener();

packages/runtime/container-runtime/src/blobManager/blobManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ export class BlobManager {
871871
const redirectTableEntries = [...this.redirectTable.entries()];
872872
for (const [localId, detachedStorageId] of redirectTableEntries) {
873873
const newStorageId = detachedStorageTable.get(detachedStorageId);
874-
assert(newStorageId !== undefined, "Couldn't find a matching storage ID");
874+
assert(newStorageId !== undefined, 0xc53 /* Couldn't find a matching storage ID */);
875875
this.setRedirection(localId, newStorageId);
876876
// set identity (id -> id) entry
877877
this.setRedirection(newStorageId, newStorageId);

packages/runtime/test-runtime-utils/src/assertionShortCodesMap.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ export const shortCodeMap = {
9595
"0x078": "Possible re-entrancy! Summary should not already be in progress.",
9696
"0x079": "Possible re-entrancy! Summary should have been in progress.",
9797
"0x07a": "Services should be there to attach delta handler",
98-
"0x07b": "Unexpected op",
9998
"0x07c": "Unexpected op type",
100-
"0x07d": "Unexpected op",
10199
"0x07e": "Unexpected op type",
102100
"0x07f": "clientId undefined",
103101
"0x080": "Invalid document service!",
@@ -376,7 +374,6 @@ export const shortCodeMap = {
376374
"0x250": "serialized container with attachment blobs must be rehydrated with detached blob storage",
377375
"0x251": "creation summary has to have seq=0 && handle === undefined",
378376
"0x252": "redirect table can only be set in detached container",
379-
"0x254": "unrecognized id in redirect table",
380377
"0x258": "connected",
381378
"0x25b": "Caller is responsible for checking lock",
382379
"0x25d": "We should never connect as 'read'",
@@ -510,13 +507,10 @@ export const shortCodeMap = {
510507
"0x37f": "reentrancy?",
511508
"0x380": "reentrancy?",
512509
"0x381": "processDeltas() should run async",
513-
"0x382": "'redirectTable' must contain only undefined while detached / defined values while attached",
514-
"0x383": "requesting unknown blobs",
515510
"0x384": "requesting handle for unknown blob",
516511
"0x385": "For clarity and paranoid defense against adding future attachment states",
517512
"0x386": "Must have pending blob entry for uploaded blob",
518513
"0x38f": "local online BlobAttach op with no pending blob entry",
519-
"0x390": "Must be attached to get GC data",
520514
"0x391": "Redirect table size must match BlobManager's local ID count",
521515
"0x395": "it's one and the same thing",
522516
"0x397": "Unexpected summary stage",
@@ -573,10 +567,7 @@ export const shortCodeMap = {
573567
"0x3fa": "Invalid interleaving of before/after slide",
574568
"0x3fe": "id must exist on the interval",
575569
"0x3ff": "pos2 should not be undefined here",
576-
"0x400": "Unexpected op",
577570
"0x401": "Unexpected op type",
578-
"0x402": "pendingIds is empty",
579-
"0x403": "Removed complete op id does not match",
580571
"0x404": "Optional fields only support a single child node",
581572
"0x406": "can only nextNode when in Nodes",
582573
"0x408": "PathNode must be alive",
@@ -776,8 +767,6 @@ export const shortCodeMap = {
776767
"0x5ad": "Cannot change the markerId of an existing marker",
777768
"0x5b0": "parent must exist",
778769
"0x5b9": "Cannot exit inexistent transaction",
779-
"0x5bb": "Must be attached to run GC",
780-
"0x5bc": "Must be attached to run GC",
781770
"0x5bd": "Invalid blob node path",
782771
"0x5c0": "AttributionCollection channel update should have consistent segment length",
783772
"0x5c1": "local attribution keys should never be put in summaries",
@@ -1869,5 +1858,30 @@ export const shortCodeMap = {
18691858
"0xc37": "Unexpected pending data for createSubDirectory op",
18701859
"0xc38": "Unexpected pending data for deleteSubDirectory op",
18711860
"0xc39": "Subdirectory should exist",
1872-
"0xc3a": "seqData should be defined"
1861+
"0xc3a": "seqData should be defined",
1862+
"0xc3b": "Not a TaskManager operation",
1863+
"0xc3c": "No pending ops for task",
1864+
"0xc3d": "Unexpected op",
1865+
"0xc3e": "No pending ops for task",
1866+
"0xc3f": "Unexpected op",
1867+
"0xc40": "No pending ops for task",
1868+
"0xc41": "Unexpected op",
1869+
"0xc42": "No pending ops for task on resubmit attempt",
1870+
"0xc43": "Could not match pending op on resubmit attempt",
1871+
"0xc44": "clientId undefined",
1872+
"0xc45": "Expect localOpMetadata to be a number",
1873+
"0xc46": "No pending ops when trying to rollback",
1874+
"0xc47": "pending op mismatch",
1875+
"0xc48": "Expected node",
1876+
"0xc49": "Expected field",
1877+
"0xc4a": "Expected node",
1878+
"0xc4b": "Expected field",
1879+
"0xc4c": "Expected field",
1880+
"0xc4d": "Expected node",
1881+
"0xc4e": "attach should happen in a node",
1882+
"0xc4f": "Should not have a dispose function without listeners",
1883+
"0xc50": "childrenChangedAfterBatch should have arg",
1884+
"0xc51": "Event handler disposed.",
1885+
"0xc52": "Buffered kernel events should have been flushed before disposing.",
1886+
"0xc53": "Couldn't find a matching storage ID"
18731887
};

0 commit comments

Comments
 (0)