Converting to int halts rendering if the input is not a number
#793
Replies: 4 comments
-
|
I'm not entirely sure I understand what you are trying to accomplish I have to admit. Are you asking about how to convert the error into a string that can be displayed or are you asking how to get the output that was evaluated and discarded, prior to the error that occurred? |
Beta Was this translation helpful? Give feedback.
-
|
My goal is to prevent Maybe it's better to say I'd like to be able to handle the problem in the template. Getting the error converted into something I can display (or otherwise use in the template) would be perfect. |
Beta Was this translation helpful? Give feedback.
-
|
You can always register a custom filter that does not error and returns |
Beta Was this translation helpful? Give feedback.
-
|
right on. i'll take a look at the custom filter approach |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I'm reading a variable that's passed in from a content source file. It comes in as text. I convert it to a number with
int. The problem is that if the content contains a letter instead of a number the page doesn't render.Reproduction steps
Here's an example of what I'm seeing:
The output is:
The input is user generated. I don't have a way to guarantee it's a number.
Additional helpful information:
What did you expect
My first guess is that the result would be
none. Whatever the actual case, I expected the page to render at least something instead of throwing an error at the.render()level that prevents output.The docs list the return type as
Result<Value, Error>. That makes sense, but I'd like to be able to ensure the page renders if an Error occurs (I can handle the presentation issues in the template).Is there a way to allow that to happen?
Beta Was this translation helpful? Give feedback.
All reactions