All files / src/exceptions MissingBindingError.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 4028x                                           28x                       21x 21x 21x      
import { MissingCapabilityError } from '@bayudwiyansatria/core'
 
/**
 * Error thrown when a binding is requested but not present on the environment.
 *
 * Bindings are resolved at request time, so a missing binding means the Worker
 * was deployed without it declared in `wrangler.json` — this error names the
 * binding so the misconfiguration is obvious in the logs.
 *
 * @remarks
 * Extends
 * `MissingCapabilityError`, so
 * a caller that wants to handle "something this deployment needs is absent"
 * without caring which platform said so can catch the base. The message stays
 * Cloudflare-specific because that is the one an operator has to act on.
 *
 * @class
 *
 * @author Bayu Dwiyan Satria
 * @version 1.0.0
 * @since 1.0.0
 */
export class MissingBindingError extends MissingCapabilityError {
  /**
   * The binding name that could not be resolved.
   */
  public readonly binding: string
 
  /**
   * Constructs a MissingBindingError.
   *
   * @param binding The binding name that could not be resolved.
   */
  constructor(binding: string) {
    super(binding, `Missing Cloudflare binding '${binding}'. Declare it in wrangler.json and redeploy.`)
    this.name = 'MissingBindingError'
    this.binding = binding
  }
}