translate commands on error
This commit is contained in:
@ -2,7 +2,10 @@
|
||||
/* eslint-disable no-inline-comments */
|
||||
import { Transform } from 'stream';
|
||||
import { GraphStreamJSON } from '../interfaces/GraphStreamJSON';
|
||||
import { GraphStreamCommand } from '../enums/GraphStreamCommand';
|
||||
import {
|
||||
GraphStreamCommand,
|
||||
translate_command
|
||||
} from '../enums/GraphStreamCommand';
|
||||
import { validate_name } from '../Helper';
|
||||
|
||||
interface Stringable {
|
||||
@ -12,7 +15,7 @@ interface Stringable {
|
||||
|
||||
export class GraphStream extends Transform {
|
||||
private _path: string[] = [];
|
||||
private _state = '';
|
||||
private _state: GraphStreamCommand | '' = '';
|
||||
private _directional = false;
|
||||
|
||||
public get path (): string {
|
||||
@ -24,7 +27,7 @@ export class GraphStream extends Transform {
|
||||
}
|
||||
|
||||
private expect_state (instr: GraphStreamCommand): void {
|
||||
const states = [];
|
||||
const states: (GraphStreamCommand|'')[] = [];
|
||||
if ([
|
||||
'cug',
|
||||
'cdg'
|
||||
@ -50,9 +53,11 @@ export class GraphStream extends Transform {
|
||||
break;
|
||||
}
|
||||
if (!states.includes (this._state)) {
|
||||
throw new Error (`invalid state to execute command ${instr}
|
||||
expected: ${states.join (', ')}
|
||||
actual: ${this._state}`);
|
||||
throw new Error (`invalid state to execute command ${
|
||||
translate_command (instr)}
|
||||
expected: ${states.map ((s) => translate_command (s))
|
||||
.join (', ')}
|
||||
actual: ${translate_command (this._state)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user