Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More detailed error messages for GitHub store CRUD operations #751

Merged

Conversation

jackdbd
Copy link
Contributor

@jackdbd jackdbd commented Jun 6, 2024

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 jackdbd changed the title Add debug logs in GitHub store CRUD operations More detailed error messages for GitHub store CRUD operations Jun 6, 2024
@paulrobertlloyd
Copy link
Collaborator

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
Copy link
Collaborator

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

@jackdbd
Copy link
Contributor Author

jackdbd commented Jun 10, 2024

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;
};

@paulrobertlloyd paulrobertlloyd force-pushed the main branch 7 times, most recently from f94062a to 1996a3d Compare August 24, 2024 19:18
@paulrobertlloyd paulrobertlloyd merged commit c606991 into getindiekit:main Aug 24, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants