fixing insufficient coverage of error_callback

This commit is contained in:
2020-05-28 18:46:35 +02:00
parent c18d216d2e
commit 5dfdb39af6
7 changed files with 43 additions and 21 deletions

View File

@ -11,13 +11,14 @@ import fs from 'fs-extra';
import { run_regex } from '@sapphirecode/utilities';
import hjson from 'hjson';
import { OptionProcess } from '../Option';
import { ErrorCallback } from '../Types/ErrorCallback';
import { OptionSource } from './OptionSource';
export class ConfigSource extends OptionSource {
private _config_files: string[];
public constructor (config_files: string[]) {
super ();
public constructor (error_callback?:ErrorCallback, config_files: string[]) {
super (error_callback);
this._config_files = config_files;
}
@ -53,7 +54,8 @@ export class ConfigSource extends OptionSource {
for (const key of Object.keys (json))
data[key] = json[key];
}
catch {
catch (e) {
this.error_callback ('*', `config file: ${f}`, e);
continue;
}
}

View File

@ -14,8 +14,11 @@ import { OptionSource } from './OptionSource';
export class InteractiveSource extends OptionSource {
private _exit_on_interrupt: boolean;
public constructor (exit_on_interrupt: boolean) {
super ();
public constructor (
error_callback?:ErrorCallback,
exit_on_interrupt: boolean
) {
super (error_callback);
this._exit_on_interrupt = exit_on_interrupt;
}

View File

@ -6,10 +6,17 @@
*/
import { OptionProcess } from '../Option';
import { ErrorCallback } from '../Types/ErrorCallback';
export abstract class OptionSource {
public abstract async parse(opt: OptionProcess[]): Promise<void>;
protected error_callback?: ErrorCallback;
public constructor (error_callback?: ErrorCallback) {
this.error_callback = error_callback;
}
protected async assign_arg (
opt: OptionProcess,
value: unknown
@ -19,8 +26,8 @@ export abstract class OptionSource {
opt.filled = true;
}
catch (e) {
if (typeof opt.error_callback !== 'undefined')
opt.error_callback (opt.name, value, e);
if (typeof this.error_callback !== 'undefined')
this.error_callback (opt.name, value, e);
}
}
}