Hoc errors

From openreachtech/hora-skills-ort-core · View interactive version

Hoc errors is an AI agent skill from the GitHub repository openreachtech/hora-skills-ort-core. Conventions for how code reports a failure, from a method that cannot produce its value to an abstract member a subclass has not implemented. Use when a method can fail, when the failure of a call to a delegate is turned into a result, or when declaring an abstract member. The string an error carrie

How to use this skill

Skill file

Shared: Errors

Summarizes conventions for error handling.

Generation methods return null on failure

// OK: return null when generation is not possible
/**
 * @param {{
 *   length: number
 * }} params - Parameters.
 * @returns {string | null} Generated text, or null if it cannot be generated.
 */
generate ({
  length,
}) {
  if (!Number.isInteger(length) || length < 0) {
    return null
  }

  // ...
}

A delegate's failure turned into a result

failure as a result rather than throwing it, how the call is laid out belongs to

/hoc-classes-delegation.

isolated in an invoke~ member that catches nothing, and the try/catch belongs to the

public member that calls it.

How an abstract member declares itself unimplemented

An abstract method or getter that requires an override in a subclass throws where it is

reached without one. Two throws express that, and a module takes one of them throughout.

| Route | What is thrown | Where it belongs |

| :-- | :-- | :-- |

| The plain error | new Error() carrying the wording below | The default, and the whole of it for a module that declares no error class of its own |

| The module's own error | The class that module declares for its failures | A module whose errors are part of what it publishes |

The choice belongs to the module and is made once. A module mixing the two leaves a caller

unable to say what to catch: half of its abstract members arrive as something the caller can

identify and half as a bare Error, and nothing about a member says which it will be.

Two rules hold whichever route is taken — how the member is named, and that the class name is

resolved rather than written down. Both are below the two routes.

The plain error

`${<class name>}<member-notation> must be inherited`
// OK: instance method (override required in subclass)
normalizeValue () {
  throw new Error(`${this.constructor.name}#normalizeValue() must be inherited`)
}

// OK: static getter
static get rawSchema () {
  throw new Error(`${this.name}.get:rawSchema must be inherited`)
}

// OK: static method
static generateCredential () {
  throw new Error(`${this.name}.generateCredential() must be inherited`)
}

The module's own error

**A module that declares an error class so its exceptions can be told apart from anything

else's has already said how its failures arrive.** An abstract member left unimplemented is

that module's own contract failing, so it arrives the same way — and a bare Error thrown

beside it would be the one failure of that module a caller cannot place.

an error code and a value, the code and the value are what a reader sees; the

must be inherited wording belongs to the plain route and is not restated here.

failure of this kind takes. This convention settles that the throw happens and what it

carries the member under, never how the string identifying it is built.

buys on the other route — whoever searches for where a member is declared abstract has one

string to search for, rather than a shape that differs per module.

// OK: the module's own error, with the member named and the class resolved
static get config () {
  throw ConcreteMemberNotFoundError.create({
    value: {
      memberName: `${this.name}.get:config`,
    },
  })
}

whether callers are meant to catch that module's failures by type; a module nobody catches

that way gains nothing from the class and takes the plain route.

The member is named as the documentation convention names it

(instance method #instanceMethod() / static getter .get:staticGetter / static method

.staticMethod(), etc.).

carries. The notation is what a reader matches against the source, so it cannot differ by

route.

The class name is resolved at run time

inherited by a subclass — which is the one case the throw exists to report, since a base

class reporting its own name says nothing about which subclass failed to override.

object rather than in a template literal next to the member. Resolve it there too.

// NG: class name is hard-coded (still displays "CompositeScalar" even in a subclass) + wording and trailing period are not unified
static get boundSchema () {
  throw new Error('CompositeScalar.get:boundSchema must be overridden.')
}

// OK: dynamically resolved, wording unified, no trailing period
static get boundSchema () {
  throw new Error(`${this.name}.get:boundSchema must be inherited`)
}
// NG: the module's own error, with the class name written down
static get config () {
  throw ConcreteMemberNotFoundError.create({
    value: {
      memberName: 'BaseServerEngine.get:config',
    },
  })
}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.