From f73a386916e8e6f842d4912b8935878322060f1c Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Fri, 4 Aug 2023 22:47:24 +0800 Subject: [PATCH] `errors/Report` -- has `entries` --- TODO.md | 12 ++++++------ src/lang/errors/InternalError.ts | 5 ----- src/lang/errors/Report.ts | 15 +++++++++++++++ src/lang/errors/index.ts | 2 +- src/lang/run/releaseFreePorts.ts | 5 +---- 5 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 src/lang/errors/InternalError.ts create mode 100644 src/lang/errors/Report.ts diff --git a/TODO.md b/TODO.md index 546d5027..b533e20f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,15 +1,15 @@ # error report -`errors/Report` -- has `entries` - -- `report.add(entry)` -- `report.format()` -- `ReportEntry` -- has `message` `span` `text` - `formatWord` `cut` throw `Report` +`report.add(entry)` + +`report.format()` + +`ReportEntry` -- has `message` `span` `text` + `RunCommand` catch `report` and call `format` # type diff --git a/src/lang/errors/InternalError.ts b/src/lang/errors/InternalError.ts deleted file mode 100644 index 0dcaa7a1..00000000 --- a/src/lang/errors/InternalError.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class InternalError extends Error { - constructor(public message: string) { - super(message) - } -} diff --git a/src/lang/errors/Report.ts b/src/lang/errors/Report.ts new file mode 100644 index 00000000..463a5915 --- /dev/null +++ b/src/lang/errors/Report.ts @@ -0,0 +1,15 @@ +import { Span } from "../span" + +export type ReportEntry = { + message: string + span: Span + text: string +} + +export class Report extends Error { + entries: Array = [] + + constructor(message: string) { + super(message) + } +} diff --git a/src/lang/errors/index.ts b/src/lang/errors/index.ts index a0cb254d..e982fd44 100644 --- a/src/lang/errors/index.ts +++ b/src/lang/errors/index.ts @@ -1,2 +1,2 @@ -export * from "./InternalError" export * from "./ParsingError" +export * from "./Report" diff --git a/src/lang/run/releaseFreePorts.ts b/src/lang/run/releaseFreePorts.ts index 488052e9..67dd28e2 100644 --- a/src/lang/run/releaseFreePorts.ts +++ b/src/lang/run/releaseFreePorts.ts @@ -1,4 +1,3 @@ -import { InternalError } from "../errors" import { Node } from "../graph/Node" import { Net } from "../net" import { disconnect } from "../net/disconnect" @@ -15,9 +14,7 @@ export function releaseFreePorts(net: Net, closer: Node | undefined): void { } if (port.connection === undefined) { - throw new InternalError( - `[releaseFreePorts] I expect port to have connection.`, - ) + throw new Error(`[releaseFreePorts] I expect port to have connection.`) } net.ports.push(port.connection.port)