indiekit icon indicating copy to clipboard operation
indiekit copied to clipboard

More detailed error messages for GitHub store CRUD operations

Open jackdbd opened this issue 1 year ago • 3 comments

This PR tries to improve the error messages a user can encounter when performing CRUD operations on the GitHub content store. It also adds a few debug logs useful when troubleshooting such operations.

The debug logs of this PR can be selectively enabled by setting the DEBUG environment variable:

DEBUG="indiekit-store:github"

jackdbd avatar Jun 06 '24 09:06 jackdbd

This PR brings up a useful question I’ve been pondering; should plugins extend from a base class (i.e. class GithubStore extends IndiekitPluginStore or similar). And if they did, would what you’ve added here be available to inherit from a base class?

It’d be nice to have consistent error output from all content stores, and not have to write an error helper for each plugin (or depend on plugin authors providing such error messages).

Do you have any views on extending a base class? I’ve avoided it until now as seemed like unnecessary complexity, but this has me wondering if there might be a case for doing so.

paulrobertlloyd avatar Jun 09 '24 14:06 paulrobertlloyd

(That said, the error messaging here is quite bespoke to GitHub… so maybe extending a base class is still overkill).

paulrobertlloyd avatar Jun 09 '24 14:06 paulrobertlloyd

I almost never create classes. Here I just wanted to follow what Indiekit was doing. I like to be able to understand what the software is doing just by enabling debug logs.

Keep in mind that you can create multiple debug functions in the same module. This is useful when your JS module is rather big and/or one particular function has some complex logic that you want to inspect carefully.

To keep debug logs consistent, I just define some constants. For example each Indiekit plugin could define a constants.js where it defines a prefix, namely a string to be used in all debug log messages.

import makeDebug from "debug";
import { FEATURE_PREFIX } from '../constants.js'

const MODULE_PREFIX= 'abc'

const debugFoo = makeDebug(`${FEATURE_PREFIX}:${MODULE_PREFIX}:foo`);
const debugBar = makeDebug(`${FEATURE_PREFIX}:${MODULE_PREFIX}:bar`);

export const foo = () => {
  debugFoo("do easy stuff");
  return 1+2;
};

export const bar = () => {
  let n=1;
  debugBar("do complex stuff");
  n = n*2;
  debugBar("do complex stuff some more");
  return n*3;
};

jackdbd avatar Jun 10 '24 09:06 jackdbd