diff --git a/packages/protons-runtime/src/index.ts b/packages/protons-runtime/src/index.ts index 8c61d59..f2f9cb5 100644 --- a/packages/protons-runtime/src/index.ts +++ b/packages/protons-runtime/src/index.ts @@ -339,12 +339,63 @@ export interface Reader { sfixed64String(): string } +/** + * This will be removed in a future release + * + * @deprecated + */ export class CodeError extends Error { public code: string - constructor (message: string, code: string, options?: ErrorOptions) { - super(message, options) + constructor (message: string, code: string) { + super(message) this.code = code } } + +/** + * Thrown when a repeated field has too many elements + */ +export class MaxLengthError extends Error { + /** + * This will be removed in a future release + * + * @deprecated use the `.name` property instead + */ + public code = 'ERR_MAX_LENGTH' + public name = 'MaxLengthError' +} + +/** + * Thrown when a map has too many elements + */ +export class MaxSizeError extends Error { + /** + * This will be removed in a future release + * + * @deprecated use the `.name` property instead + */ + public code = 'ERR_MAX_SIZE' + public name = 'MaxSizeError' +} + +export class ParseError extends Error { + /** + * This will be removed in a future release + * + * @deprecated use the `.name` property instead + */ + public code = 'ERR_PARSE_ERROR' + public name = 'ParseError' +} + +export class NoMessagesFoundError extends Error { + /** + * This will be removed in a future release + * + * @deprecated use the `.name` property instead + */ + public code = 'ERR_NO_MESSAGES_FOUND' + public name = 'NoMessagesFoundError' +} diff --git a/packages/protons/package.json b/packages/protons/package.json index e45ab6c..1eca733 100644 --- a/packages/protons/package.json +++ b/packages/protons/package.json @@ -49,14 +49,14 @@ }, "dependencies": { "meow": "^13.1.0", - "protobufjs-cli": "^1.0.0" + "protobufjs-cli": "^1.0.0", + "protons-runtime": "^5.0.0" }, "devDependencies": { "aegir": "^44.1.0", "long": "^5.2.0", "pbjs": "^0.0.14", "protobufjs": "^7.0.0", - "protons-runtime": "^5.0.0", "uint8arraylist": "^2.4.3", "uint8arrays": "^5.0.1" } diff --git a/packages/protons/src/index.ts b/packages/protons/src/index.ts index 532c611..1be1cbd 100644 --- a/packages/protons/src/index.ts +++ b/packages/protons/src/index.ts @@ -195,6 +195,7 @@ import fs from 'fs/promises' import path from 'path' import { promisify } from 'util' import { main as pbjs } from 'protobufjs-cli/pbjs.js' +import { NoMessagesFoundError, ParseError } from 'protons-runtime' export enum CODEC_TYPES { VARINT = 0, @@ -210,6 +211,11 @@ function pathWithExtension (input: string, extension: string, outputDir?: string return path.join(output, path.basename(input).split('.').slice(0, -1).join('.') + extension) } +/** + * This will be removed in a future release + * + * @deprecated + */ export class CodeError extends Error { public code: string @@ -659,7 +665,7 @@ function compileMessage (messageDef: MessageDef, moduleDef: ModuleDef, flags?: F const message = `enum ${messageDef.name} does not contain a value that maps to zero as it's first element, this is required in proto3 - see https://protobuf.dev/programming-guides/proto3/#enum` if (flags?.strict === true) { - throw new CodeError(message, 'ERR_PARSE_ERROR') + throw new ParseError(message) } else { // eslint-disable-next-line no-console console.info(`[WARN] ${message}`) @@ -923,18 +929,18 @@ export interface ${messageDef.name} { : decoderGenerators[type](jsTypeOverride)}` if (fieldDef.map) { - moduleDef.addImport('protons-runtime', 'CodeError') + moduleDef.addImport('protons-runtime', 'MaxSizeError') let limit = ` if (opts.limits?.${fieldName} != null && obj.${fieldName}.size === opts.limits.${fieldName}) { - throw new CodeError('decode error - map field "${fieldName}" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "${fieldName}" had too many elements') } ` if (fieldDef.lengthLimit != null) { limit += ` if (obj.${fieldName}.size === ${fieldDef.lengthLimit}) { - throw new CodeError('decode error - map field "${fieldName}" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "${fieldName}" had too many elements') } ` } @@ -945,18 +951,18 @@ export interface ${messageDef.name} { break }` } else if (fieldDef.repeated) { - moduleDef.addImport('protons-runtime', 'CodeError') + moduleDef.addImport('protons-runtime', 'MaxLengthError') let limit = ` if (opts.limits?.${fieldName} != null && obj.${fieldName}.length === opts.limits.${fieldName}) { - throw new CodeError('decode error - map field "${fieldName}" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "${fieldName}" had too many elements') } ` if (fieldDef.lengthLimit != null) { limit += ` if (obj.${fieldName}.length === ${fieldDef.lengthLimit}) { - throw new CodeError('decode error - repeated field "${fieldName}" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - repeated field "${fieldName}" had too many elements') } ` } @@ -1110,7 +1116,7 @@ function defineModule (def: ClassDef, flags: Flags): ModuleDef { const defs = def.nested if (defs == null) { - throw new CodeError('No top-level messages found in protobuf', 'ERR_NO_MESSAGES_FOUND') + throw new NoMessagesFoundError('No top-level messages found in protobuf') } function defineMessage (defs: Record, parent?: ClassDef, flags?: Flags): void { @@ -1138,7 +1144,7 @@ function defineModule (def: ClassDef, flags: Flags): ModuleDef { const message = `field "${name}" is required, this is not allowed in proto3. Please convert your proto2 definitions to proto3 - see https://github.com/ipfs/protons/wiki/Required-fields-and-protobuf-3` if (flags?.strict === true) { - throw new CodeError(message, 'ERR_PARSE_ERROR') + throw new ParseError(message) } else { fieldDef.proto2Required = true diff --git a/packages/protons/test/fixtures/bitswap.ts b/packages/protons/test/fixtures/bitswap.ts index f679e40..59cef9a 100644 --- a/packages/protons/test/fixtures/bitswap.ts +++ b/packages/protons/test/fixtures/bitswap.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' @@ -180,7 +180,7 @@ export namespace Message { switch (tag >>> 3) { case 1: { if (opts.limits?.entries != null && obj.entries.length === opts.limits.entries) { - throw new CodeError('decode error - map field "entries" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "entries" had too many elements') } obj.entries.push(Message.Wantlist.Entry.codec().decode(reader, reader.uint32(), { @@ -438,7 +438,7 @@ export namespace Message { } case 2: { if (opts.limits?.blocks != null && obj.blocks.length === opts.limits.blocks) { - throw new CodeError('decode error - map field "blocks" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "blocks" had too many elements') } obj.blocks.push(reader.bytes()) @@ -446,7 +446,7 @@ export namespace Message { } case 3: { if (opts.limits?.payload != null && obj.payload.length === opts.limits.payload) { - throw new CodeError('decode error - map field "payload" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "payload" had too many elements') } obj.payload.push(Message.Block.codec().decode(reader, reader.uint32(), { @@ -456,7 +456,7 @@ export namespace Message { } case 4: { if (opts.limits?.blockPresences != null && obj.blockPresences.length === opts.limits.blockPresences) { - throw new CodeError('decode error - map field "blockPresences" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "blockPresences" had too many elements') } obj.blockPresences.push(Message.BlockPresence.codec().decode(reader, reader.uint32(), { diff --git a/packages/protons/test/fixtures/circuit.ts b/packages/protons/test/fixtures/circuit.ts index f21362a..264661f 100644 --- a/packages/protons/test/fixtures/circuit.ts +++ b/packages/protons/test/fixtures/circuit.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' @@ -128,7 +128,7 @@ export namespace CircuitRelay { } case 2: { if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { - throw new CodeError('decode error - map field "addrs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') } obj.addrs.push(reader.bytes()) diff --git a/packages/protons/test/fixtures/daemon.ts b/packages/protons/test/fixtures/daemon.ts index 395cd03..f0ec651 100644 --- a/packages/protons/test/fixtures/daemon.ts +++ b/packages/protons/test/fixtures/daemon.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' @@ -320,7 +320,7 @@ export namespace Response { } case 6: { if (opts.limits?.peers != null && obj.peers.length === opts.limits.peers) { - throw new CodeError('decode error - map field "peers" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "peers" had too many elements') } obj.peers.push(PeerInfo.codec().decode(reader, reader.uint32(), { @@ -411,7 +411,7 @@ export namespace IdentifyResponse { } case 2: { if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { - throw new CodeError('decode error - map field "addrs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') } obj.addrs.push(reader.bytes()) @@ -494,7 +494,7 @@ export namespace ConnectRequest { } case 2: { if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { - throw new CodeError('decode error - map field "addrs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') } obj.addrs.push(reader.bytes()) @@ -581,7 +581,7 @@ export namespace StreamOpenRequest { } case 2: { if (opts.limits?.proto != null && obj.proto.length === opts.limits.proto) { - throw new CodeError('decode error - map field "proto" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "proto" had too many elements') } obj.proto.push(reader.string()) @@ -662,7 +662,7 @@ export namespace StreamHandlerRequest { } case 2: { if (opts.limits?.proto != null && obj.proto.length === opts.limits.proto) { - throw new CodeError('decode error - map field "proto" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "proto" had too many elements') } obj.proto.push(reader.string()) @@ -1131,7 +1131,7 @@ export namespace PeerInfo { } case 2: { if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { - throw new CodeError('decode error - map field "addrs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') } obj.addrs.push(reader.bytes()) @@ -1507,7 +1507,7 @@ export namespace PSMessage { } case 4: { if (opts.limits?.topicIDs != null && obj.topicIDs.length === opts.limits.topicIDs) { - throw new CodeError('decode error - map field "topicIDs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "topicIDs" had too many elements') } obj.topicIDs.push(reader.string()) @@ -1590,7 +1590,7 @@ export namespace PSResponse { switch (tag >>> 3) { case 1: { if (opts.limits?.topics != null && obj.topics.length === opts.limits.topics) { - throw new CodeError('decode error - map field "topics" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "topics" had too many elements') } obj.topics.push(reader.string()) @@ -1598,7 +1598,7 @@ export namespace PSResponse { } case 2: { if (opts.limits?.peerIDs != null && obj.peerIDs.length === opts.limits.peerIDs) { - throw new CodeError('decode error - map field "peerIDs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "peerIDs" had too many elements') } obj.peerIDs.push(reader.bytes()) @@ -1703,7 +1703,7 @@ export namespace PeerstoreRequest { } case 3: { if (opts.limits?.protos != null && obj.protos.length === opts.limits.protos) { - throw new CodeError('decode error - map field "protos" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "protos" had too many elements') } obj.protos.push(reader.string()) @@ -1781,7 +1781,7 @@ export namespace PeerstoreResponse { } case 2: { if (opts.limits?.protos != null && obj.protos.length === opts.limits.protos) { - throw new CodeError('decode error - map field "protos" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "protos" had too many elements') } obj.protos.push(reader.string()) diff --git a/packages/protons/test/fixtures/dht.ts b/packages/protons/test/fixtures/dht.ts index ebe259c..e22f942 100644 --- a/packages/protons/test/fixtures/dht.ts +++ b/packages/protons/test/fixtures/dht.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface Record { @@ -212,7 +212,7 @@ export namespace Message { } case 2: { if (opts.limits?.addrs != null && obj.addrs.length === opts.limits.addrs) { - throw new CodeError('decode error - map field "addrs" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "addrs" had too many elements') } obj.addrs.push(reader.bytes()) @@ -321,7 +321,7 @@ export namespace Message { } case 8: { if (opts.limits?.closerPeers != null && obj.closerPeers.length === opts.limits.closerPeers) { - throw new CodeError('decode error - map field "closerPeers" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "closerPeers" had too many elements') } obj.closerPeers.push(Message.Peer.codec().decode(reader, reader.uint32(), { @@ -331,7 +331,7 @@ export namespace Message { } case 9: { if (opts.limits?.providerPeers != null && obj.providerPeers.length === opts.limits.providerPeers) { - throw new CodeError('decode error - map field "providerPeers" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "providerPeers" had too many elements') } obj.providerPeers.push(Message.Peer.codec().decode(reader, reader.uint32(), { diff --git a/packages/protons/test/fixtures/maps.ts b/packages/protons/test/fixtures/maps.ts index 001cf81..d293030 100644 --- a/packages/protons/test/fixtures/maps.ts +++ b/packages/protons/test/fixtures/maps.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, MaxSizeError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export enum EnumValue { @@ -72,7 +72,7 @@ export namespace SubMessage { } case 2: { if (opts.limits?.bar != null && obj.bar.length === opts.limits.bar) { - throw new CodeError('decode error - map field "bar" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "bar" had too many elements') } obj.bar.push(reader.uint32()) @@ -530,7 +530,7 @@ export namespace MapTypes { switch (tag >>> 3) { case 1: { if (opts.limits?.stringMap != null && obj.stringMap.size === opts.limits.stringMap) { - throw new CodeError('decode error - map field "stringMap" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "stringMap" had too many elements') } const entry = MapTypes.MapTypes$stringMapEntry.codec().decode(reader, reader.uint32()) @@ -539,7 +539,7 @@ export namespace MapTypes { } case 2: { if (opts.limits?.intMap != null && obj.intMap.size === opts.limits.intMap) { - throw new CodeError('decode error - map field "intMap" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "intMap" had too many elements') } const entry = MapTypes.MapTypes$intMapEntry.codec().decode(reader, reader.uint32()) @@ -548,7 +548,7 @@ export namespace MapTypes { } case 3: { if (opts.limits?.boolMap != null && obj.boolMap.size === opts.limits.boolMap) { - throw new CodeError('decode error - map field "boolMap" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "boolMap" had too many elements') } const entry = MapTypes.MapTypes$boolMapEntry.codec().decode(reader, reader.uint32()) @@ -557,7 +557,7 @@ export namespace MapTypes { } case 4: { if (opts.limits?.messageMap != null && obj.messageMap.size === opts.limits.messageMap) { - throw new CodeError('decode error - map field "messageMap" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "messageMap" had too many elements') } const entry = MapTypes.MapTypes$messageMapEntry.codec().decode(reader, reader.uint32(), { @@ -570,7 +570,7 @@ export namespace MapTypes { } case 5: { if (opts.limits?.enumMap != null && obj.enumMap.size === opts.limits.enumMap) { - throw new CodeError('decode error - map field "enumMap" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "enumMap" had too many elements') } const entry = MapTypes.MapTypes$enumMapEntry.codec().decode(reader, reader.uint32()) diff --git a/packages/protons/test/fixtures/peer.ts b/packages/protons/test/fixtures/peer.ts index 2628df4..afbff9f 100644 --- a/packages/protons/test/fixtures/peer.ts +++ b/packages/protons/test/fixtures/peer.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc' import type { Uint8ArrayList } from 'uint8arraylist' @@ -75,7 +75,7 @@ export namespace Peer { switch (tag >>> 3) { case 1: { if (opts.limits?.addresses != null && obj.addresses.length === opts.limits.addresses) { - throw new CodeError('decode error - map field "addresses" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "addresses" had too many elements') } obj.addresses.push(Address.codec().decode(reader, reader.uint32(), { @@ -85,7 +85,7 @@ export namespace Peer { } case 2: { if (opts.limits?.protocols != null && obj.protocols.length === opts.limits.protocols) { - throw new CodeError('decode error - map field "protocols" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "protocols" had too many elements') } obj.protocols.push(reader.string()) @@ -93,7 +93,7 @@ export namespace Peer { } case 3: { if (opts.limits?.metadata != null && obj.metadata.length === opts.limits.metadata) { - throw new CodeError('decode error - map field "metadata" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "metadata" had too many elements') } obj.metadata.push(Metadata.codec().decode(reader, reader.uint32(), { diff --git a/packages/protons/test/fixtures/protons-options.ts b/packages/protons/test/fixtures/protons-options.ts index 5601fe5..be17b98 100644 --- a/packages/protons/test/fixtures/protons-options.ts +++ b/packages/protons/test/fixtures/protons-options.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, MaxSizeError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface MessageWithSizeLimitedRepeatedField { @@ -44,11 +44,11 @@ export namespace MessageWithSizeLimitedRepeatedField { switch (tag >>> 3) { case 1: { if (opts.limits?.repeatedField != null && obj.repeatedField.length === opts.limits.repeatedField) { - throw new CodeError('decode error - map field "repeatedField" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "repeatedField" had too many elements') } if (obj.repeatedField.length === 1) { - throw new CodeError('decode error - repeated field "repeatedField" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - repeated field "repeatedField" had too many elements') } obj.repeatedField.push(reader.string()) @@ -185,11 +185,11 @@ export namespace MessageWithSizeLimitedMap { switch (tag >>> 3) { case 1: { if (opts.limits?.mapField != null && obj.mapField.size === opts.limits.mapField) { - throw new CodeError('decode error - map field "mapField" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "mapField" had too many elements') } if (obj.mapField.size === 1) { - throw new CodeError('decode error - map field "mapField" had too many elements', 'ERR_MAX_SIZE') + throw new MaxSizeError('Decode error - map field "mapField" had too many elements') } const entry = MessageWithSizeLimitedMap.MessageWithSizeLimitedMap$mapFieldEntry.codec().decode(reader, reader.uint32()) diff --git a/packages/protons/test/fixtures/repeated.ts b/packages/protons/test/fixtures/repeated.ts index 97489c9..637c2f3 100644 --- a/packages/protons/test/fixtures/repeated.ts +++ b/packages/protons/test/fixtures/repeated.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export interface SubSubMessage { @@ -50,7 +50,7 @@ export namespace SubSubMessage { switch (tag >>> 3) { case 1: { if (opts.limits?.foo != null && obj.foo.length === opts.limits.foo) { - throw new CodeError('decode error - map field "foo" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "foo" had too many elements') } obj.foo.push(reader.string()) @@ -141,7 +141,7 @@ export namespace SubMessage { switch (tag >>> 3) { case 1: { if (opts.limits?.foo != null && obj.foo.length === opts.limits.foo) { - throw new CodeError('decode error - map field "foo" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "foo" had too many elements') } obj.foo.push(reader.string()) @@ -159,7 +159,7 @@ export namespace SubMessage { } case 4: { if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) { - throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "messages" had too many elements') } obj.messages.push(SubSubMessage.codec().decode(reader, reader.uint32(), { @@ -257,7 +257,7 @@ export namespace RepeatedTypes { switch (tag >>> 3) { case 1: { if (opts.limits?.number != null && obj.number.length === opts.limits.number) { - throw new CodeError('decode error - map field "number" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "number" had too many elements') } obj.number.push(reader.uint32()) @@ -265,11 +265,11 @@ export namespace RepeatedTypes { } case 2: { if (opts.limits?.limitedNumber != null && obj.limitedNumber.length === opts.limits.limitedNumber) { - throw new CodeError('decode error - map field "limitedNumber" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "limitedNumber" had too many elements') } if (obj.limitedNumber.length === 1) { - throw new CodeError('decode error - repeated field "limitedNumber" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - repeated field "limitedNumber" had too many elements') } obj.limitedNumber.push(reader.uint32()) @@ -277,7 +277,7 @@ export namespace RepeatedTypes { } case 3: { if (opts.limits?.messages != null && obj.messages.length === opts.limits.messages) { - throw new CodeError('decode error - map field "messages" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "messages" had too many elements') } obj.messages.push(SubMessage.codec().decode(reader, reader.uint32(), { diff --git a/packages/protons/test/fixtures/test.ts b/packages/protons/test/fixtures/test.ts index cd86ecd..0210e53 100644 --- a/packages/protons/test/fixtures/test.ts +++ b/packages/protons/test/fixtures/test.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ /* eslint-disable @typescript-eslint/no-empty-interface */ -import { type Codec, CodeError, decodeMessage, type DecodeOptions, encodeMessage, enumeration, message } from 'protons-runtime' +import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, enumeration, MaxLengthError, message } from 'protons-runtime' import type { Uint8ArrayList } from 'uint8arraylist' export enum AnEnum { @@ -275,7 +275,7 @@ export namespace AllTheTypes { } case 14: { if (opts.limits?.field14 != null && obj.field14.length === opts.limits.field14) { - throw new CodeError('decode error - map field "field14" had too many elements', 'ERR_MAX_LENGTH') + throw new MaxLengthError('Decode error - map field "field14" had too many elements') } obj.field14.push(reader.string())