Skip to content

Commit a126068

Browse files
crussokrpeacock
andauthored
Update packages/candid/src/idl.ts
Co-authored-by: Kaia Peacock <[email protected]>
1 parent e366eb6 commit a126068

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/candid/src/idl.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -922,15 +922,19 @@ export class OptClass<T> extends ConstructType<[T] | []> {
922922
case 0:
923923
return [];
924924
case 1: {
925+
// Save the current state of the Pipe `b` to allow rollback in case of an error
925926
const checkpoint = b.save();
926927
try {
927-
const v = this._type.decodeValue(b, opt._type)
928+
// Attempt to decode a value using the `_type` of the current instance
929+
const v = this._type.decodeValue(b, opt._type);
930+
// If decoding succeeds, return the value wrapped in an array
928931
return [v];
929-
} catch (e : any) {
932+
} catch (e: any) {
933+
// If an error occurs during decoding, restore the Pipe `b` to its previous state
930934
b.restore(checkpoint);
931-
// skip value at wire type (to advance b)
932-
const v = opt._type.decodeValue(b, opt._type)
933-
// retun none
935+
// Skip the value at the current wire type to advance the Pipe `b` position
936+
opt._type.decodeValue(b, opt._type);
937+
// Return an empty array to indicate a `none` value
934938
return [];
935939
}
936940
}

0 commit comments

Comments
 (0)