theRAPTLab / gsgo

GEM-STEP Foundation repo migrated from GitLab June 2023
1 stars 1 forks source link

DRAFT: Feature: Error Manager (WIP) - [merged] #699

Closed benloh closed 1 year ago

benloh commented 2 years ago

In GitLab by @daveseah on Jul 19, 2022, 17:06

Merges dev-next-gui-errhelp -> dev-next

WORK IN PROGRESS

WHAT IS THE ERROR MANAGER

The Error Manager is a module that is being designed to centralize capture, processing, and reporting of errors across GEMSTEP.

The Error Manager technically does the following:

With the above in place, we can do stuff like this:

DEVELOPMENT APPROACH

Because error management can significantly change workflow in unexpected ways, we're developing it in a separate branch: dev-next-gui-errhelp. This branch will track against the active branch used by the research team (dev-next-gui at the time of this writing), merging in changes as they are made. This should result in an alternate branch that researchers can try out; if there is a consensus that it's ready for use, we can merge it quickly.

This is a fairly complicated subject because of the number of error sources, their specific meaning, and context of operation; we are implementing a kind of 1980s style "expert system" using ad-hoc techniques. On the technical side, there is also inserting the additional code to check for errors programmatically, and handling cascading errors where an error may originate in one area and then cause a number of cascading failures in parallel. Determining which error is the "root cause" that should be reported to the user.

Right now we are just trying to catch them all; afterwards we can concentrate on providing the first-pass user experience:

This work will require a lot of coordination between the GUI, system, and research team to communicate what errors they are seeing and how they believe they should be handled.

INITIAL TECHNICAL DESIGN

copied from !245

reporting errors from code

First import ERROR from 'modules/error-mgr' in the module you're adding to the error reporting system.

Your code can use try/catch with this format:

try {
  const script_tokens = TRANSPILER.TextToScript(suspiciousText);
  const program = TRANSPILER.CompileScript(script_tokens);
} catch (caught) {
  ERROR(`error detected`,{
    source:'compiler',
    where: 'name-of-module, function',
    data: { suspiciousText },
    caught
  }
}

The ERROR method logs the error and contextual information, and rethrows the passed caught error object back up the chain IF "system wide error handling" is enabled by the SYSTEM_ENABLE flag defined in the modules/error-mgr source. If this flag is off, the error is just logged by the error is not rethrown so things can sort of run further, but it's unlikely it will do so cleanly.

After an error is logged, the system waits for 1500 milliseconds before throwing an overlay up on the browser window telling you that an error has occurred, and what to do about it.

checking error status (WIP)

For modules that care whether an error has happened or not, use code that look like this:

import { ERR_MGR } from 'modules/error-mgr'

function mySpecialCode() {
  // stuff that could make errors happen in here
}

if (!ERR_MGR) mySpecialCode();
else try {
  mySpecialCode()
} catch (caught) {
  ERR_MGR(`an error occurred`, {   
    source:'compiler',
    where: 'name-of-module, function',
    data: { suspiciousText },
    caught
  }
} 

This awkward syntax is used to make two versions of the code that is run with the try/catch wrapper. ERR_MGR will be valid if SYSTEM_ENABLE is set true in modules/error-mgr, undefined if not. This isn't a great solution, so we'll see what we can do to make it more streamlined.

CONDITIONS CURRENTLY CHECKED AND TRAPPED

Here are the current cases that the error manager is now trying to detect during operation

benloh commented 2 years ago

In GitLab by @daveseah on Jul 19, 2022, 17:06

changed target branch from dev to dev-next-gui

benloh commented 2 years ago

In GitLab by @daveseah on Jul 20, 2022, 13:37

added 2 commits

Compare with previous version

benloh commented 2 years ago

In GitLab by @daveseah on Jul 20, 2022, 14:23

added 1 commit

Compare with previous version

benloh commented 2 years ago

In GitLab by @daveseah on Jul 27, 2022, 10:56

changed target branch from dev-next-gui to dev-next

benloh commented 2 years ago

In GitLab by @daveseah on Jul 27, 2022, 17:40

added 75 commits

Compare with previous version