# Possible to error if variable declaration cannot be resolved?

**URL:** <https://forum.serverless.com/t/possible-to-error-if-variable-declaration-cannot-be-resolved/2454>\
**Category:** Serverless Framework\
**Created:** [August 9, 2017, 2:07pm UTC](https://forum.serverless.com/t/possible-to-error-if-variable-declaration-cannot-be-resolved/2454 "2017-08-09T14:07:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![breathe](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/breathe/32/859_2.png) [@breathe](https://forum.serverless.com/u/breathe)\
**Post date:** [August 9, 2017, 2:07pm UTC](https://forum.serverless.com/t/possible-to-error-if-variable-declaration-cannot-be-resolved/2454/1 "2017-08-09T14:07:57Z")

</div>

Is there a way to get serverless to error and quit execution if a variable declaration cannot be resolved rather than just issue a warning?

```
 Serverless Warning --------------------------------------

  A valid service attribute to satisfy the declaration 'self:custom.config.HEALTHCARE_PREMIUM_TABLE' could not be found.
```

---

<div class="post-metadata">

**Author:** ![breathe](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/breathe/32/859_2.png) [@breathe](https://forum.serverless.com/u/breathe)\
**Post date:** [August 10, 2017, 5:31am UTC](https://forum.serverless.com/t/possible-to-error-if-variable-declaration-cannot-be-resolved/2454/2 "2017-08-10T05:31:02Z")

</div>

If anyone is interested - here’s a hacky way I found to do this with a custom plugin …

```
import { isEmpty } from "lodash";

/**
 * Serverless Plugin which turns missing variable warnings into errors
 */
export class MissingVariableShouldErrorPlugin {
  constructor(serverless: any, _: any) {
    const variables = serverless.variables;
    const originalWarningMethod = variables.warnIfNotFound;

    const monkeyPatchWarnIfNotFoundMethod = function(
      this: any,
      variableString: any,
      valueToPopulate: any
    ) {
      originalWarningMethod.apply(this, [variableString, valueToPopulate]);
      if (
        valueToPopulate === null ||
        typeof valueToPopulate === "undefined" ||
        (typeof valueToPopulate === "object" && isEmpty(valueToPopulate))
      ) {
        throw Error(`Undefined variable: ${variableString}`);
      }
    };

    variables.warnIfNotFound = monkeyPatchWarnIfNotFoundMethod;
  }
}
```
