Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement typed errors #2229

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Implement typed errors #2229

merged 1 commit into from
Aug 29, 2024

Conversation

Borewit
Copy link
Owner

@Borewit Borewit commented Aug 28, 2024

This PR standardizes the error handling in the parsing module by introducing specific error classes, ensuring all thrown errors are of the type ParseErrorType. This enhancement improves type safety, clarity, and consistency across the codebase.

Changes Introduced

The following custom error classes have been introduced to represent specific parsing errors:

  • CouldNotDetermineFileTypeError: Thrown when the parser cannot determine the file type.
  • UnsupportedFileTypeError: Thrown when an unsupported file type is encountered.
  • UnexpectedFileContentError: Thrown when the file content does not match the expected format.
  • InternalParserError: Thrown in case of an internal error during parsing.

Unified Error Type

All the above error classes are grouped under a new union type, KindOfParseError, which provides a common structure for parsing-related

type KindOfParseError = 
  | CouldNotDetermineFileTypeError
  | UnsupportedFileTypeError
  | UnexpectedFileContentError
  | InternalParserError;

Each error class shares a common name property, which is useful for error identification and handling (switching).

PR suggestion provided by sponsor @schickling:

One thing that would be great as well would be to have improved error paths
Eg typed errors

@schickling can you please review?

@Borewit Borewit self-assigned this Aug 28, 2024
@coveralls
Copy link

coveralls commented Aug 28, 2024

Coverage Status

coverage: 97.078% (-0.01%) from 97.092%
when pulling 9bd97bd on custom-error-class
into 04fd5ee on master.

@Borewit Borewit force-pushed the custom-error-class branch 2 times, most recently from c7036d5 to cd49d4d Compare August 28, 2024 18:35
@Borewit Borewit changed the title Implement own custom Error: ParseError Implement typed errors Aug 28, 2024
@Borewit Borewit force-pushed the custom-error-class branch 4 times, most recently from 253ff83 to be904b6 Compare August 29, 2024 15:10
@Borewit Borewit merged commit 8fe9ac2 into master Aug 29, 2024
25 checks passed
@Borewit Borewit deleted the custom-error-class branch August 29, 2024 15:48
@Borewit
Copy link
Owner Author

Borewit commented Aug 29, 2024

Part of v10.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants