How to use the cog.error function in cog

To help you get started, we’ve selected a few cog 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 jgarvin / Cogflect / cog-recipes / cogflect / GeneratorBase.py View on Github external
verifyName(field_name)
                setattr(field, field_name, value)
            self.fields.append(field)

        fieldNames = [f.name for f in self.fields]
        maybeDupe = hasDupes(fieldNames)
        if maybeDupe:
            cog.error("You can't specify the same field name twice. "
                      "Name specified twice: " + maybeDupe)

        for f in self.fields:
            if hasattr(f, "tags") and f.tags != None:
                if type(f.tags) == list:
                    maybeDupe = hasDupes(f.tags)
                    if maybeDupe:
                        cog.error("You can't specify the same tag twice "
                                  " on the same field. "
                                  "Tag specified twice: " + maybeDupe +
                                  " on field: " + f.name)
                    self.possible_tags.update(f.tags)
                elif type(f.tags) == set:
                    self.possible_tags.update(f.tags)
                else:
                    self.possible_tags.add(f.tags)
                    f.tags = [f.tags]
            else:
                f.tags = []

            for t in f.tags:
                verifyName(t)

            if not hasattr(f, "metadata") or f.metadata == None:
github jgarvin / Cogflect / cog-recipes / cogflect / util.py View on Github external
def verifyName(name):
    "Protects against use of invalid variable names."

    # TODO: Whitespace/empty check
    if name == "":
        cog.error("Empty strings cannot be used for names.")

    if name.isspace():
        cog.error("Names must include non-whitespace characters.")

    prohibited = ["and", "and_eq",
                  "alignas", "alignof", "asm", "auto", "bitand", "bitor", "bool", "break",
                  "case", "catch", "char", "char16_t", "char32_t", "class", "compl", "const",
                  "constexpr", "const_cast", "continue", "decltype", "default", "delete", "double", "dynamic_cast",
                  "else", "enum", "explicit", "export", "extern", "false", "float", "for",
                  "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace",
                  "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq",
                  "private", "protected", "public", "register", "reinterpret_cast", "return", "short", "signed",
                  "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this",
                  "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union",
                  "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor",
                  "xor_eq"]
github jgarvin / Cogflect / cog-recipes / cogflect / util.py View on Github external
def verifyName(name):
    "Protects against use of invalid variable names."

    # TODO: Whitespace/empty check
    if name == "":
        cog.error("Empty strings cannot be used for names.")

    if name.isspace():
        cog.error("Names must include non-whitespace characters.")

    prohibited = ["and", "and_eq",
                  "alignas", "alignof", "asm", "auto", "bitand", "bitor", "bool", "break",
                  "case", "catch", "char", "char16_t", "char32_t", "class", "compl", "const",
                  "constexpr", "const_cast", "continue", "decltype", "default", "delete", "double", "dynamic_cast",
                  "else", "enum", "explicit", "export", "extern", "false", "float", "for",
                  "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace",
                  "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq",
                  "private", "protected", "public", "register", "reinterpret_cast", "return", "short", "signed",
                  "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this",
                  "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union",
                  "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor",
                  "xor_eq"]

    if name in prohibited:
        cog.error("Cannot use \"%s\" as a name. It is a C++ keyword. "
github jgarvin / Cogflect / cog-recipes / cogflect / GeneratorBase.py View on Github external
assert type(fields[0]) == list

        for column in self.schema:
            assert type(column) == str

        for row in fields[1:]:
            field = _object()
            for field_name, value in zip(self.schema, row):
                verifyName(field_name)
                setattr(field, field_name, value)
            self.fields.append(field)

        fieldNames = [f.name for f in self.fields]
        maybeDupe = hasDupes(fieldNames)
        if maybeDupe:
            cog.error("You can't specify the same field name twice. "
                      "Name specified twice: " + maybeDupe)

        for f in self.fields:
            if hasattr(f, "tags") and f.tags != None:
                if type(f.tags) == list:
                    maybeDupe = hasDupes(f.tags)
                    if maybeDupe:
                        cog.error("You can't specify the same tag twice "
                                  " on the same field. "
                                  "Tag specified twice: " + maybeDupe +
                                  " on field: " + f.name)
                    self.possible_tags.update(f.tags)
                elif type(f.tags) == set:
                    self.possible_tags.update(f.tags)
                else:
                    self.possible_tags.add(f.tags)