How to use the yay.errors.Error function in yay

To help you get started, we’ve selected a few yay examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yaybu / yaybu / yaybu / core / command.py View on Github external
self.lastcmd = ''
        if cmd == '':
            return self.default(line)
        else:
            try:
                func = getattr(self, 'do_' + cmd)
            except AttributeError:
                return self.default(line)
            parser = self.parser()
            optparse_func = getattr(self, 'opts_' + cmd, lambda x: x)
            optparse_func(parser)
            opts, args = parser.parse_args(arg.split())

            try:
                return func(opts, args)
            except yay.errors.Error as e:
                if getattr(self, "debug", False):
                    import pdb
                    pdb.post_mortem()
                print e.get_string()
                return getattr(e, "returncode", 128)
            except KeyboardInterrupt:
                print "^C"
github yaybu / yaybu / yaybu / dns.py View on Github external
def _get_zone_by_domain(self, domain):
        zones = [z for z in self.driver.list_zones() if z.domain == domain]

        if len(zones) > 1:
            raise errors.Error(
                "Found multiple zones that match domain name '%s'" % domain)
        elif len(zones) == 1:
            return zones[0]
github yaybu / yaybu / yaybu / util / templates.py View on Github external
def _call_render(template, *args, **kwargs):
    try:
        return template.render(*args, **kwargs)
    except errors.Error as e:
        # Don't intercept valid Yaybu errors
        raise
    except UndefinedError as e:
        tb = sys.exc_info()[2]
        raise error.NoMatching(str(e), anchor=JinjaTracebackAnchor(template, tb))
    except BaseException as e:
        tb = sys.exc_info()[2]
        raise error.TemplateError("The template engine was unable to fill in your template and reported: '%s'" % str(e), anchor=JinjaTracebackAnchor(template, tb))
github yaybu / yaybu / yaybu / dns.py View on Github external
driver = self.driver

        domain = self.params.domain.as_string().rstrip(".") + "."
        zone = self._get_zone_by_domain(domain)

        change = ZoneSync(
            expression=self.params,
            driver=driver,
            zone=zone,
        ).apply(self.root)

        if not zone:
            zone = self._get_zone_by_domain(domain)

        if not self.root.simulate and not zone:
            raise errors.Error("Failed to create new zone")

        rchange = RecordSync(
            expression=self.params,
            driver=driver,
            zone=zone,
            purge_remote=not self.params.shared.as_bool(default=True),
        ).apply(self.root)

        self.root.changed(change.changed or rchange.changed)