From a424101ee363a772e877125274d36fe019cbe823 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 21 May 2020 08:57:13 -0500 Subject: [PATCH] feat: error handling --- packages/net/packet/packet.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/net/packet/packet.js b/packages/net/packet/packet.js index 4134b65..65a8cce 100644 --- a/packages/net/packet/packet.js +++ b/packages/net/packet/packet.js @@ -9,7 +9,20 @@ export class Packet { static get builder() { if (!this._builder) { - this._builder = schemapack.build(this.schema); + const schema = this.schema; + if (!schema._id) { + throw new Error([ + `No packet id found in '${this.name}.schema'. This is usually due to forgetting to`, + 'inherit from Packet.schema within your packet subclass schema definition.', + ].join(' ')); + } + if (!schema.data) { + throw new Error([ + `No data found in '${this.name}.schema'. This is usually due to forgetting to`, + 'inherit from Packet.schema within your packet subclass schema definition.', + ].join(' ')); + } + this._builder = schemapack.build(schema); } return this._builder; }