Errors¶
Error handling and exception classes for HED validation and processing.
Exception Classes¶
HedFileError¶
HedFileError ¶
Bases: Exception
Exception raised when a file cannot be parsed due to being malformed, file IO, etc.
Source code in hed/errors/exceptions.py
HedExceptions¶
HedExceptions ¶
HED exception codes.
Source code in hed/errors/exceptions.py
Error Reporting¶
ErrorHandler¶
ErrorHandler ¶
Class to hold error context and having general error functions.
Source code in hed/errors/error_reporter.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
add_context_and_filter ¶
Filter out warnings if requested, while adding context to issues.
issues(list): list: A list containing a single dictionary representing a single error.
Source code in hed/errors/error_reporter.py
aggregate_code_counts
staticmethod
¶
Aggregate the counts of codes across multiple files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_code_dict
|
dict
|
A dictionary where keys are filenames and values are dictionaries of code counts. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary with the aggregated counts of codes across all files. |
Source code in hed/errors/error_reporter.py
filter_issues_by_count
staticmethod
¶
Filter the issues list to only include the first count issues of each code.
Parameters:
issues (list): A list of dictionaries containing the full issue list.
count (int): The number of issues to keep for each code.
by_file (bool): If True, group by file name.
Returns:
Type | Description |
---|---|
tuple[list[dict], dict[str, int]]
|
tuple[list[dict], dict[str, int]]: A tuple containing: - A list of dictionaries representing the filtered issue list. - A dictionary with the codes as keys and the number of occurrences as values. |
Source code in hed/errors/error_reporter.py
filter_issues_by_severity
staticmethod
¶
Gather all issues matching or below a given severity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
issues_list
|
list[dict]
|
A list of dictionaries containing the full issue list. |
required |
severity
|
int
|
The level of issues to keep. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of dictionaries containing the issue list after filtering by severity. |
Source code in hed/errors/error_reporter.py
format_error
staticmethod
¶
Format an error based on the parameters, which vary based on what type of error this is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_type
|
str
|
The type of error for this. Registered with @hed_error or @hed_tag_error. |
required |
args
|
args
|
Any remaining non-keyword args after those required by the error type. |
()
|
actual_error
|
str or None
|
Code to actually add to report out. |
None
|
kwargs
|
kwargs
|
The other keyword args to pass down to the error handling func. |
{}
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list containing a single dictionary representing a single error. |
Notes
The actual error is useful for errors that are shared like invalid character.
Source code in hed/errors/error_reporter.py
format_error_from_context
staticmethod
¶
format_error_from_context(
error_type: str,
error_context: list,
*args,
actual_error: Optional[str],
**kwargs
) -> list[dict]
Format an error based on the error type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error_type
|
str
|
The type of error. Registered with @hed_error or @hed_tag_error. |
required |
error_context
|
list
|
Contains the error context to use for this error. |
required |
args
|
args
|
Any remaining non-keyword args. |
()
|
actual_error
|
str or None
|
Error code to actually add to report out. |
required |
kwargs
|
kwargs
|
Keyword parameters to pass down to the error handling func. |
{}
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list containing a single dictionary. |
Notes
- Generally the error_context is returned from _add_context_to_error.
- The actual_error is useful for errors that are shared like invalid character.
- This can't filter out warnings like the other ones.
Source code in hed/errors/error_reporter.py
pop_error_context ¶
Remove the last scope from the error context.
Notes
Modifies the error context of this reporter.
push_error_context ¶
Push a new error context to narrow down error scope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context_type
|
str
|
A value from ErrorContext representing the type of scope. |
required |
context
|
str, int, or HedString
|
The main value for the context_type. |
required |
Notes
The context depends on the context_type. For ErrorContext.FILE_NAME this would be the actual filename.
Source code in hed/errors/error_reporter.py
reset_error_context ¶
Reset all error context information to defaults.
Notes
This function is mainly for testing and should not be needed with proper usage.
val_error_unknown ¶
Default error handler if no error of this type was registered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
args
|
List of non-keyword parameters (varies). |
()
|
kwargs
|
kwargs
|
Keyword parameters (varies) |
{}
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The error message. |
Source code in hed/errors/error_reporter.py
ErrorContext¶
ErrorContext ¶
Context this error took place in, each error potentially having multiple contexts.
Source code in hed/errors/error_types.py
Error Types¶
ErrorSeverity¶
ErrorSeverity ¶
ValidationErrors¶
ValidationErrors ¶
Source code in hed/errors/error_types.py
SidecarErrors¶
SidecarErrors ¶
Source code in hed/errors/error_types.py
Schema Error Messages¶
schema_error_messages ¶
Format templates for HED schema error messages.