error cleanup, alert the error

Clean up the error to break out of sequence when we encounter an error for efficiency. Then for now use alert to show the user an error of some kind. This is temporary until I can style some kind of new module for errors.
This commit is contained in:
Grayson Lorenz 2020-04-25 10:48:45 -05:00
parent b3055bc271
commit cee304e976
2 changed files with 35 additions and 13 deletions

View File

@ -104,6 +104,32 @@ export class Logger {
this.handler({ time: new Date(), message, severity, logger: this, cause }, this.name);
}
}
showTrace = (message: string, cause?: any): void => {
this.showLog(Severity.Trace, message, cause);
};
showDebug = (message: string, cause?: any): void => {
this.showLog(Severity.Debug, message, cause);
};
showInfo = (message: string, cause?: any): void => {
this.showLog(Severity.Info, message, cause);
};
showWarn = (message: string, cause?: any): void => {
this.showLog(Severity.Warning, message, cause);
};
showError = (message: string, cause?: any): void => {
this.showLog(Severity.Error, message, cause);
};
//for graphically showing errors and other messages, assume we always want this to show, otherwise we wouldn't call it.
//Instead of doing an alert, we should have some better styled area, like a dismissable bar at the top of the screen with the error.
showLog(severity: Severity, message: string, cause?: any): void {
alert('Message: ' + message + '\r\n\r\nCause: ' + cause.message);
}
}
export class LogManager {

View File

@ -152,17 +152,12 @@ export class QuestEditorToolBarController extends Controller {
const parse_result = parse_qst_to_quest(
new ArrayBufferCursor(buffer, Endianness.Little),
);
if (parse_result) {
quest = parse_result.quest;
this.set_version(parse_result.version);
if (!parse_result || !parse_result.quest) {
throw new Error("Couldn't parse quest file.");
}
quest = parse_result.quest;
this.set_version(parse_result.version);
this.set_filename(basename(qst.name));
if (!quest) {
logger.error("Couldn't parse quest file.");
}
} else {
const bin = files.find(f => f.name.toLowerCase().endsWith(".bin"));
const dat = files.find(f => f.name.toLowerCase().endsWith(".dat"));
@ -174,11 +169,12 @@ export class QuestEditorToolBarController extends Controller {
new ArrayBufferCursor(bin_buffer, Endianness.Little),
new ArrayBufferCursor(dat_buffer, Endianness.Little),
);
this.set_filename(basename(bin.name || dat.name));
if (!quest) {
logger.error("Couldn't parse quest file.");
throw new Error("Couldn't parse bin or dat file.");
}
this.set_filename(basename(bin.name || dat.name));
} else {
throw new Error("Invalid File Type.");
}
}
@ -186,7 +182,7 @@ export class QuestEditorToolBarController extends Controller {
quest && convert_quest_to_model(this.area_store, quest),
);
} catch (e) {
logger.error("Couldn't read file.", e);
logger.showError("Couldn't read file.", e);
}
};