Skip to content

Use custom error classes instead of generic errors#1701

Merged
joelhawksley merged 34 commits intomainfrom
896-error-cleanup
Apr 4, 2023
Merged

Use custom error classes instead of generic errors#1701
joelhawksley merged 34 commits intomainfrom
896-error-cleanup

Conversation

@joelhawksley
Copy link
Member

What are you trying to accomplish?

The goal of this PR is to add all of our error messages to our docs. In order to do so, I moved all of our errors to an Errors module and had YARD look for classes ending in Error that have a MESSAGE constant.

I also cleaned up a few errors that should have been removed previously. I'll follow up with a review of our error messages themselves.

What do y'all think of the names for these errors?

…textCalledBeforeRenderError`, removing `ViewContextCalledBeforeRenderError`.
Copy link
Contributor

@camertron camertron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow this is awesome! 🎉

@path = ::File.realpath(params.permit(:file)[:file], base_path)
unless @path.start_with?(base_path)
raise ArgumentError, "Invalid file path"
raise ViewComponent::SystemTestControllerNefariousPathError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol "nefarious"

Comment on lines +9 to +12
MESSAGE =
"It looks like a block was provided after calling `with_content` on COMPONENT, " \
"which means that ViewComponent doesn't know which content to use.\n\n" \
"To fix this issue, use either `with_content` or a block."
Copy link
Contributor

@camertron camertron Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would these look better as squiggly heredocs?

Suggested change
MESSAGE =
"It looks like a block was provided after calling `with_content` on COMPONENT, " \
"which means that ViewComponent doesn't know which content to use.\n\n" \
"To fix this issue, use either `with_content` or a block."
MESSAGE = <<~MESSAGE
It looks like a block was provided after calling `with_content` on COMPONENT,
which means that ViewComponent doesn't know which content to use.
To fix this issue, use either `with_content` or a block.
MESSAGE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure these lines are equivalent, though? I'm trying to have the first sentence of the output be a single line of text.

Copy link
Member Author

@joelhawksley joelhawksley Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed in the console: => "It looks like a block was provided after calling with_content on COMPONENT,\n

@joelhawksley joelhawksley merged commit 841bd3b into main Apr 4, 2023
@joelhawksley joelhawksley deleted the 896-error-cleanup branch April 4, 2023 19:02
claudiob pushed a commit to claudiob/view_component that referenced this pull request Dec 22, 2023
* BREAKING: Use `HelpersCalledBeforeRenderError` in place of `ViewContextCalledBeforeRenderError`.

* BREAKING: Use `TranslateCalledBeforeRenderError` in place of `ViewContextCalledBeforeRenderError`, removing `ViewContextCalledBeforeRenderError`.

* BREAKING: Raise `NilWithContentError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::ReservedPluralSlotNameError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::InvalidSlotDefinitionError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::ContentSlotNameError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::ReservedSingularSlotNameError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::RedefinedSlotError` instead of `ArgumentError`.

* let's be real these are just going to be squashed

* finish slotable errors

* system test controller errors

* add preview helper custom errors

* add DuplicateContentError

* add custom error classes for collections

* ReservedParameterError instead of generic class

* InvalidCollectionArgumentError instead of generic error

* allow components to redefine with_content

* fix warning

* use MultipleInlineTemplatesError

* raise MissingPreviewTemplateError

* move TemplateError to Errors module

* raise DuplicateSlotContentError

* remove untested and likely unused error case in tests

* syntax

* Revert "remove untested and likely unused error case in tests"

This reverts commit 00cdb0c.

* fix failing test

* fix failing test

* lints

* thank you Vale

* fix failing test

* capitalization

* mdlint

* fix failing test
claudiob pushed a commit to claudiob/view_component that referenced this pull request Jan 3, 2024
* BREAKING: Use `HelpersCalledBeforeRenderError` in place of `ViewContextCalledBeforeRenderError`.

* BREAKING: Use `TranslateCalledBeforeRenderError` in place of `ViewContextCalledBeforeRenderError`, removing `ViewContextCalledBeforeRenderError`.

* BREAKING: Raise `NilWithContentError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::ReservedPluralSlotNameError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::InvalidSlotDefinitionError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::ContentSlotNameError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::ReservedSingularSlotNameError` instead of `ArgumentError`.

* BREAKING: Raise `ViewComponent::RedefinedSlotError` instead of `ArgumentError`.

* let's be real these are just going to be squashed

* finish slotable errors

* system test controller errors

* add preview helper custom errors

* add DuplicateContentError

* add custom error classes for collections

* ReservedParameterError instead of generic class

* InvalidCollectionArgumentError instead of generic error

* allow components to redefine with_content

* fix warning

* use MultipleInlineTemplatesError

* raise MissingPreviewTemplateError

* move TemplateError to Errors module

* raise DuplicateSlotContentError

* remove untested and likely unused error case in tests

* syntax

* Revert "remove untested and likely unused error case in tests"

This reverts commit 00cdb0c.

* fix failing test

* fix failing test

* lints

* thank you Vale

* fix failing test

* capitalization

* mdlint

* fix failing test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants