Class: Blufin::YmlErrorHandler

Inherits:
Object
  • Object
show all
Extended by:
Columnist
Defined in:
lib/core/error_handling/yml_error_handler.rb

Constant Summary collapse

FILE_EMPTY =
1000
FILE_INVALID =
1005
FILE_NOT_FOUND =
1010
TEST_NOT_FOUND =
1011
FILE_NOT_FOUND_GITIGNORE =
1011
FILE_NOT_EXPECTED =
1020
TEST_NOT_EXPECTED =
1021
FILE_CONTENT_MISMATCH =
1030
DIRECTORY_NOT_FOUND =
1050
DIRECTORY_NOT_EXPECTED =
1060
SECTION_ORDER =
1100
SECTION_TITLE_REGEX =
1110
SECTION_VALUE_REGEX =
1111
SECTION_ALPHABETICAL =
1120
ARRAY_KEY_ROGUE =
1130
ARRAY_VALUE_REGEX =
1131
ARRAY_VALUE_BLANK =
1132
ARRAY_STRING_EXPECTED =
1133
ARRAY_HASHES_EXPECTED =
1134
ANNOTATIONS_ONE_OR_ANOTHER =
1150
ANNOTATIONS_NOT_EXPECTED =
1151
FIELD_MISSING_EMPTY =
1200
FIELD_BOOLEAN =
1210
FIELD_FILE =
1220
FIELD_TEXT_CAPITALIZED =
1230
FIELD_TEXT_REGEX =
1240
FIELD_TEXT_NOT_DEFINED =
1250
FIELD_ROGUE =
1260
FIELD_UNNECESSARY =
1270
FIELD_MISSING =
1279
FIELD_ORDER =
1280
FIELD_INVALID_VALUE =
1285
FIELD_INVALID_TYPE =
1286
FIELD_REQUIRES_SUB_FIELDS =
1287
FIELD_CANNOT_BE_BLANK =
1288
FIELD_NAME_TRANSIENT_CONFLICT =
1289
STYLE_MULTIPLE_BLANK_LINES =
1300
STYLE_TRAILING_BLANK_LINES =
1310
STYLE_UNRECOGNIZED_LINE =
1320
API_ENDPOINTS_MISSING =
2000
API_ENDPOINTS_NOT_ALLOWED =
2001
API_METHOD_INVALID_FOR_REQUIRED_OBJECT =
2003
CONFIG =

RESERVED

2100
CRON =

RESERVED

2200
EVENT =

RESERVED

2300
SCHEMA =

RESERVED

2400
WORKER_MESSAGE_TYPE_NOT_FOUND =
2500
DATA_NOT_ALPHABETICAL =
3000
MAVEN_MODULE_UNRECOGNIZED =
3100
MAVEN_MODULE_NOT_DEFINED =
3105
MAVEN_MODULE_NOT_REGISTERED =
3106
MAVEN_MODULE_DUPLICATE =
3110
MAVEN_MODULE_ORDER =
3115
MAVEN_MODULE_UNDEFINED_PARENT =
3116
MAVEN_MODULE_UNUSED_PARENT =
3117
EMBEDDED_OBJECT_NOT_FOUND =

EVERYTHING IN THE 5000 (OR ABOVE) RANGE PRODUCES ERRORS WITHOUT SECTION/FIELD OUTPUT (AS THEY ARE GENERALLY FILE RELATED).

5000
EMBEDDED_OBJECT_NO_ANNOTATION =
5005
EMBEDDED_OBJECT_NO_TABLE =
5006
EMBEDDED_OBJECT_INVALID_SCHEMA =
5001
EMBEDDED_OBJECT_INVALID_NAME =
5010
EMBEDDED_OBJECT_INVALID_REF_REGEX =
5011
EMBEDDED_OBJECT_INVALID_REF_LENGTH =
5012
EMBEDDED_OBJECT_INVALID_ABSTRACTION =
5015
EMBEDDED_OBJECT_INVALID_EXTENSION =
5016
EMBEDDED_OBJECT_INVALID_LINE =
5018
EMBEDDED_OBJECT_INVALID_REGEX =
5019
EMBEDDED_OBJECT_DATA_NOT_FOUND =
5020
EMBEDDED_FIELD_MISSING =
5030
EMBEDDED_FIELD_WRONG_TYPE =
5031
EMBEDDED_ANNOTATION_MISSING =
5032
EMBEDDED_ANNOTATION_UNNECESSARY =
5033
EMBEDDED_EXTRA_VALUE_INVALID =
5034
EMBEDDED_DATA_TYPE_INVALID =
5035
EMBEDDED_FLAGS_INVALID =
5036
EMBEDDED_FKEY_INVALID =
5037
EMBEDDED_MUST_BE_ENCRYPTED =
5038
EMBEDDED_CONFIG_CANNOT_BE_ENCRYPTED =
5039
UNEXPECTED_EXCEPTION =
9999
COLOR_TITLE =
123
COLOR_ERROR_MESSAGE =
242
MDASH =
"\xe2\x80\x94"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Object

Initializes the Error Handler.



179
180
181
182
183
184
185
# File 'lib/core/error_handling/yml_error_handler.rb', line 179

def initialize(site)

    @site      = Blufin::SiteResolver::validate_site(site)
    @site_path = Blufin::SiteResolver::get_site_location(@site)
    @errors    = []

end

Class Method Details

.error_type_metaObject

Returns a Hash of valid error types with titles/descriptions. Moved to top of file for easier programming.

Returns:

  • Hash



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/core/error_handling/yml_error_handler.rb', line 98

def self.error_type_meta
    {
        FILE_EMPTY                             => ['EMPTY FILE', "The YML parser expected #{Blufin::Terminal::format_action('file(s)')} to contain data:"],
        FILE_INVALID                           => ['INVALID FILE', "The YML parser was unable to parse the following #{Blufin::Terminal::format_action('file(s)')}:", 'Unable to parse: %s'],
        FILE_NOT_FOUND                         => ['FILE NOT FOUND', "The YML parser expected #{Blufin::Terminal::format_action('file(s)')} to exist:", 'File not found: %s'],
        TEST_NOT_FOUND                         => ['TEST NOT FOUND', "The YML parser expected #{Blufin::Terminal::format_action('tests(s)')} to exist (most likely due to missing #{Blufin::SiteServices::ANNOTATION_TEST_REQUIRED}):", 'Test not found: %s'],
        FILE_NOT_FOUND_GITIGNORE               => ['GITIGNORE NOT FOUND', "The YML parser expected #{Blufin::Terminal::format_action('.gitignore')} to exist:", 'File not found in: %s'],
        FILE_NOT_EXPECTED                      => ['FILE NOT EXPECTED', "The YML parser did not expect certain #{Blufin::Terminal::format_action('file(s)')} to exist:", 'Rogue file: %s'],
        TEST_NOT_EXPECTED                      => ['TEST NOT EXPECTED', "The YML parser did not expect certain #{Blufin::Terminal::format_action('test(s)')} to exist (most likely due to missing #{Blufin::SiteServices::ANNOTATION_TEST_NOT_RELATED_TO_CLASS}):", 'Rogue test: %s'],
        FILE_CONTENT_MISMATCH                  => ['FILE CONTENT MISMATCH', "The YML parser expect file(s) to have certain #{Blufin::Terminal::format_action('content(s)')} but it wasn't found:"],
        DIRECTORY_NOT_FOUND                    => ['DIRECTORY NOT FOUND', "The YML parser expected #{Blufin::Terminal::format_action('director(ies)')} to exist:", 'Directory not found: %s'],
        DIRECTORY_NOT_EXPECTED                 => ['DIRECTORY NOT EXPECTED', "The YML parser did not expect certain #{Blufin::Terminal::format_action('director(ies)')} to exist:", 'Rogue directory: %s'],
        SECTION_ORDER                          => ['SECTION ORDER MISMATCH', "The YML parser expected #{Blufin::Terminal::format_action('section(s)')} within a file to be in a certain order:"],
        SECTION_TITLE_REGEX                    => ['SECTION TITLE REGEX MISMATCH', "The YML parser expected section title to match #{Blufin::Terminal::format_action('regex')}:", '%s does not match regex: %s'],
        SECTION_VALUE_REGEX                    => ['SECTION VALUE REGEX MISMATCH', "The YML parser expected section value to match #{Blufin::Terminal::format_action('regex')}:", '%s does not match regex: %s'],
        SECTION_ALPHABETICAL                   => ['SECTION NOT ALPHABETICAL', "The YML parser expected section keys to be in #{Blufin::Terminal::format_action('alphabetical')} order:", '%s is in the wrong position.'],
        ARRAY_KEY_ROGUE                        => ['ROGUE KEY', "The YML parser did not recognize certain #{Blufin::Terminal::format_action('array key(s)')} to exist:", 'Rogue key: %s'],
        ARRAY_VALUE_REGEX                      => ['ARRAY VALUE REGEX MISMATCH', "The YML parser expected section array value to match #{Blufin::Terminal::format_action('regex')}:", '%s does not match regex: %s'],
        ARRAY_VALUE_BLANK                      => ['ARRAY VALUE BLANK', "#{Blufin::Terminal::format_action('Array value(s)')} cannot be blank:", 'Blank key: %s'],
        ARRAY_STRING_EXPECTED                  => ['STRING ARRAY EXPECTED', "The YML parser expected an #{Blufin::Terminal::format_action('Array of Strings')}:", 'Got: %s'],
        ARRAY_HASHES_EXPECTED                  => ['HASH ARRAY EXPECTED', "The YML parser expected an #{Blufin::Terminal::format_action('Array of Hashes')}:", 'Got: %s'],
        ANNOTATIONS_ONE_OR_ANOTHER             => ['ANNOTATIONS MISMATCH', "The YML parser expected either one #{Blufin::Terminal::format_action('annotation')} or another:", '%s cannot be used together.'],
        ANNOTATIONS_NOT_EXPECTED               => ['ANNOTATIONS NOT EXPECTED', "The YML parser did not expect certain #{Blufin::Terminal::format_action('annotation(s)')} to exist in file(s):", '%s cannot be used in this file.'],
        FIELD_MISSING_EMPTY                    => ['MISSING/EMPTY FIELD', "The YML parser expected certain #{Blufin::Terminal::format_action('field(s)')} to exist and not be empty:"],
        FIELD_BOOLEAN                          => ['INVALID VALUE - BOOLEAN', "Boolean fields must be #{Blufin::Terminal::format_action('TRUE')} or #{Blufin::Terminal::format_action('FALSE')}:"],
        FIELD_FILE                             => ['INVALID VALUE - FILE NOT FOUND', "The YML parser expected certain #{Blufin::Terminal::format_action('file(s)')} to exist:", 'File not found: %s'],
        FIELD_TEXT_CAPITALIZED                 => ['VALUE NOT CAPITALIZED', "The YML parser expected text in field(s) to be #{Blufin::Terminal::format_action('capitalized')}:"],
        FIELD_TEXT_REGEX                       => ['VALUE REGEX MISMATCH', "The YML parser expected text in field(s) to match #{Blufin::Terminal::format_action('regex')}:", '%s does not match regex: %s'],
        FIELD_TEXT_NOT_DEFINED                 => ['VALUE NOT DEFINED', "The YML parser expected text in field(s) to match pre-set #{Blufin::Terminal::format_action('values')}:"],
        FIELD_ROGUE                            => ['ROGUE PROPERTY', "The YML parser did not recognize certain #{Blufin::Terminal::format_action('properties')} to exist:", 'Rogue property: %s'],
        FIELD_UNNECESSARY                      => ['UNNECESSARY PROPERTY', "The following #{Blufin::Terminal::format_action('properties')} are unnecessary with the current configuration:", 'Unnecessary field: %s'],
        FIELD_MISSING                          => ['PROPERTY MISSING', "The YML parser expected #{Blufin::Terminal::format_action('properties')} within a section to exist:"],
        FIELD_ORDER                            => ['PROPERTY ORDER MISMATCH', "The YML parser expected #{Blufin::Terminal::format_action('properties')} within a section to be in a certain order:"],
        FIELD_INVALID_VALUE                    => ['PROPERTY INVALID VALUE', "The YML parser expected properties to contain a certain  #{Blufin::Terminal::format_action('value(s)')}:", 'Valid value(s): %s'],
        FIELD_INVALID_TYPE                     => ['PROPERTY INVALID TYPE', "The YML parser expected properties to to be a certain #{Blufin::Terminal::format_action('type')}:"],
        FIELD_REQUIRES_SUB_FIELDS              => ['PROPERTY REQUIRES SUB-FIELDS', "The YML parser expected properties to contain #{Blufin::Terminal::format_action('sub-properties')}:"],
        FIELD_CANNOT_BE_BLANK                  => ['PROPERTY CANNOT BE BLANK', "Optional properties -- if present -- #{Blufin::Terminal::format_action('cannot be empty')}:", 'Empty properties: %s'],
        FIELD_NAME_TRANSIENT_CONFLICT          => ['PROPERTY NAME TRANSIENT CONFLICT', "Property name conflicts with an auto-generated #{Blufin::Terminal::format_action('transient property')}:", 'Conflicting property: %s'],
        STYLE_MULTIPLE_BLANK_LINES             => ['UNNECESSARY BLANK LINE', "Unnecessary #{Blufin::Terminal::format_action('blank line(s)')} found in YML file(s):", 'Line: %s'],
        STYLE_TRAILING_BLANK_LINES             => ['TRAILING BLANK LINE(S)', "#{Blufin::Terminal::format_action('Trailing blank line(s)')} are not allowed in YML files:", 'Line: %s'],
        STYLE_UNRECOGNIZED_LINE                => ['UNRECOGNIZED LINE', "Something is wrong with this #{Blufin::Terminal::format_action('line')}. Perhaps check formatting, key-capitalization or whitespace?", 'Line: %s'],
        API_ENDPOINTS_MISSING                  => ['API END-POINTS MISSING', "The following #{Blufin::Terminal::format_action('table(s)')} require all HTTP method end-points because they are #{Blufin::Terminal::format_action(Blufin::ScannerJavaEmbeddedObjects::EMBEDDED)}:", 'Needs GET, POST, PATCH & DELETE.'],
        API_ENDPOINTS_NOT_ALLOWED              => ['API END-POINTS NOT ALLOWED', "The following #{Blufin::Terminal::format_action('table(s)')} do not allow POST/PUT/PATCH/DELETE HTTP method(s)because they are #{Blufin::Terminal::format_action(Blufin::ScannerJavaEmbeddedObjects::EMBEDDED)}:", 'Found: %s'],
        API_METHOD_INVALID_FOR_REQUIRED_OBJECT => ['API METHOD INVALID FOR REQUIRED OBJECT', "#{Blufin::Terminal::format_action(Blufin::YmlSchemaValidator::REQUIRED)} and #{Blufin::Terminal::format_action(Blufin::YmlSchemaValidator::REQUIRED_IF)} objects cannot have a #{Blufin::Terminal::format_action(Blufin::YmlConfigValidator::POST)} and/or #{Blufin::Terminal::format_action(Blufin::YmlConfigValidator::DELETE)} because they may require a parent:", 'Found: %s'],
        WORKER_MESSAGE_TYPE_NOT_FOUND          => ['INVALID MESSAGE TYPE', "The following #{Blufin::Terminal::format_action('MessageTypes(s)', false)} are not defined in the worker-service:", 'Unrecognized MessageType: %s'],
        DATA_NOT_ALPHABETICAL                  => ['DATA NOT ALPHABETICAL', "The YML parser expected the data in a section to be in #{Blufin::Terminal::format_action('alphabetical')} order:", 'Not in correct order: %s'],
        MAVEN_MODULE_UNRECOGNIZED              => ['MAVEN MODULE UNRECOGNIZED', "A maven module has been defined but #{Blufin::Terminal::format_action('not found within the file system')}:", 'Unrecognized module: %s'],
        MAVEN_MODULE_NOT_DEFINED               => ['MAVEN MODULE NOT DEFINED', "A maven module found within the file system has #{Blufin::Terminal::format_action('no definition')}:", 'Undefined module: %s'],
        MAVEN_MODULE_NOT_REGISTERED            => ['MAVEN MODULE NOT REGISTERED', "A maven module reference has #{Blufin::Terminal::format_action('not been registered')}:", 'Unregistered module: %s'],
        MAVEN_MODULE_DUPLICATE                 => ['DUPLICATE MAVEN MODULE', "A #{Blufin::Terminal::format_action('duplicate')} maven module was found:", 'Duplicate module: %s'],
        MAVEN_MODULE_ORDER                     => ['MAVEN MODULE ORDER MISMATCH', "The YML parser expected maven modules to be in #{Blufin::Terminal::format_action('alphabetical order')}:", 'Not in order: %s'],
        MAVEN_MODULE_UNDEFINED_PARENT          => ['MAVEN MODULE UNDEFINED PARENT', "A maven module parent has #{Blufin::Terminal::format_action('not been defined')}:", 'Undefined parent: %s'],
        MAVEN_MODULE_UNUSED_PARENT             => ['MAVEN MODULE UNUSED PARENT', "A maven module parent has #{Blufin::Terminal::format_action('not been used')}:", 'Unused parent: %s'],
        EMBEDDED_OBJECT_NOT_FOUND              => ['OBJECT NOT FOUND', "Java Scanner expected exactly ONE object to be #{Blufin::Terminal::format_action('embedded')} with annotation/value but it wasn't:", "Missing: #{Blufin::ScannerJavaEmbeddedObjects::EMBEDDED}(\"%s\")"],
        EMBEDDED_OBJECT_NO_ANNOTATION          => ['EMBEDDED ANNOTATION MISSING', "Java Scanner did not find an #{Blufin::Terminal::format_action(Blufin::ScannerJavaEmbeddedObjects::EMBEDDED)} annotation:", "Missing #{Blufin::ScannerJavaEmbeddedObjects::EMBEDDED} annotation:"],
        EMBEDDED_OBJECT_NO_TABLE               => ['TABLE NOT FOUND', "A required #{Blufin::Terminal::format_action('embedded object')} doesn't have a schema counter-part table:", 'Missing table: %s'],
        EMBEDDED_OBJECT_INVALID_SCHEMA         => ['INVALID OBJECT SCHEMA', "Java Scanner was unable to attribute a #{Blufin::Terminal::format_action('valid schema')} to an embedded object:", 'Unrecognized schema: %s'],
        EMBEDDED_OBJECT_INVALID_NAME           => ['INVALID OBJECT NAME', "Java Scanner was unable to resolve a #{Blufin::Terminal::format_action('valid name')} for an embedded object:", "'%s' needs to start with 'Abstract...':"],
        EMBEDDED_OBJECT_INVALID_REF_REGEX      => ['INVALID REFERENCE', "The #{Blufin::Terminal::format_action('reference')} used for an embedded object is invalid:", '%s needs to be lowercase & snake-case.'],
        EMBEDDED_OBJECT_INVALID_REF_LENGTH     => ['INVALID REFERENCE', "The #{Blufin::Terminal::format_action('reference')} used for an embedded object is invalid:", "%s needs to be less than #{Blufin::YmlSchemaValidator::MAX_TABLE_CHARACTERS} characters:"],
        EMBEDDED_OBJECT_INVALID_ABSTRACTION    => ['INVALID OBJECT ABSTRACTION', "Java Scanner expected embedded object(s) NOT to be #{Blufin::Terminal::format_action('abstract', false)}:", '%s cannot be abstract.'],
        EMBEDDED_OBJECT_INVALID_EXTENSION      => ['INVALID OBJECT INTERFACE', "Java Scanner expected embedded object to extend #{Blufin::Terminal::format_action('PersistentDtoEmbedded', false)}:", '%s needs to implement PersistentDtoEmbedded.'],
        EMBEDDED_OBJECT_INVALID_LINE           => ['INVALID LINE', "Embedded Object(s). Something is wrong with the following #{Blufin::Terminal::format_action('line(s)')}:", '%s'],
        EMBEDDED_OBJECT_INVALID_REGEX          => ['INVALID REGEX', "Embedded Object(s). Object name needs to match #{Blufin::Terminal::format_action('regex')}:", '%s does not match regex: %s'],
        EMBEDDED_OBJECT_DATA_NOT_FOUND         => ['NO DATA WITHIN OBJECT', "Java Scanner was unable to resolve #{Blufin::Terminal::format_action('fields')} for an embedded object:", 'No fields in: %s'],
        EMBEDDED_FIELD_MISSING                 => ['MISSING FIELD', "Embedded object(s) is/are missing expected #{Blufin::Terminal::format_action('fields')}:", 'Missing: %s'],
        EMBEDDED_FIELD_WRONG_TYPE              => ['WRONG FIELD TYPE', "Embedded object(s) field(s) are of incorrect #{Blufin::Terminal::format_action('type')}:"],
        EMBEDDED_ANNOTATION_MISSING            => ['MISSING ANNOTATION', "Embedded object(s) are missing expected #{Blufin::Terminal::format_action('annotations')}:", 'Missing: %s'],
        EMBEDDED_ANNOTATION_UNNECESSARY        => ['UNNECESSARY ANNOTATION', "The following embedded object(s) #{Blufin::Terminal::format_action('annotation value(s)')} are not required:", '%s'],
        EMBEDDED_EXTRA_VALUE_INVALID           => ['INVALID EXTRA VALUE', "Embedded object(s) field #{Blufin::Terminal::format_action('extra value')} is invalid:", 'Expected: %s Got: %s'],
        EMBEDDED_DATA_TYPE_INVALID             => ['INVALID DATA TYPE', "Embedded object(s) field #{Blufin::Terminal::format_action('data-type')} is invalid:", 'Expected: %s Got: %s'],
        EMBEDDED_FLAGS_INVALID                 => ['INVALID FLAGS', "Embedded object(s) field has invalid #{Blufin::Terminal::format_action('flags')}:"],
        EMBEDDED_FKEY_INVALID                  => ['INVALID/MISSING FKEY', "Embedded object(s) field has an invalid/missing #{Blufin::Terminal::format_action('fkey')} property:"],
        EMBEDDED_MUST_BE_ENCRYPTED             => ['FIELD MUST BE ENCRYPTED', "Embedded object(s) field must be #{Blufin::Terminal::format_action('encrypted')}:"],
        EMBEDDED_CONFIG_CANNOT_BE_ENCRYPTED    => ['FIELD CANNOT BE ENCRYPTED', "Embedded object(s) within the config schema cannot be #{Blufin::Terminal::format_action('encrypted')}:"],
        UNEXPECTED_EXCEPTION                   => ['UNEXPECTED EXCEPTION', "The YML parser encountered an #{Blufin::Terminal::format_action('unexpected exception')}", '%s']
    }
end

Instance Method Details

#add_error(type, file, section, field, message = nil) ⇒ Object

Adds an YmlError object to the @error Array.

Returns:

  • void



189
190
191
# File 'lib/core/error_handling/yml_error_handler.rb', line 189

def add_error(type, file, section, field, message = nil)
    @errors << Blufin::YmlError.new(validate_error_type(type), file, section, field, message)
end

#add_error_schema(error_object) ⇒ Object

Adds an SchemaError object to the @error Array.

Returns:

  • void



195
196
197
# File 'lib/core/error_handling/yml_error_handler.rb', line 195

def add_error_schema(error_object)
    @errors << error_object
end

#display_errors_if_any(exit = false) ⇒ Object

Displays errors (if any) and halts the script if so.

Returns:

  • Boolean



201
202
203
# File 'lib/core/error_handling/yml_error_handler.rb', line 201

def display_errors_if_any(exit = false)
    self.class.output_errors(@errors, @site_path, exit)
end

#get_error_countObject

Returns a count of how many errors are currently stored.

Returns:

  • Integer



207
208
209
# File 'lib/core/error_handling/yml_error_handler.rb', line 207

def get_error_count
    @errors.size
end