Hello. I'm new in the list and new user of OpenRasta too, sorry if I
make no sense.
I was going to post a message asking for help but suddenly realised I
have a similar problem as the OP of this thread (exception from codec
which I want to capture, although my exception has a slightly
different stacktrace, but still comes from the
RequestEntityReaderHydrator [1]). So I think the approach you mention
here below is the one I need to use (because I already tried with
others [2] without success), could you provide an example of how to do
what you say about hooking a contributor after result invocation
please?
Thanks!
[1] My exception is:
2011-01-12 15:01:08,049 [12] ERROR openrasta - An error has occurred
and the processing of the request has stopped.
Exception:
System.Exception: someStringThatIsNotANumber is not a valid value for
Int32. ---> System.FormatException: Input string was not in a correct
format.
at System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style,
NumberFormatInfo info)
at System.ComponentModel.Int32Converter.FromString(String value,
NumberFormatInfo formatInfo)
at
System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext
context, CultureInfo culture, Object value)
--- End of inner exception stack trace ---
at
System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext
context, CultureInfo culture, Object value)
at
OpenRasta.TypeSystem.ReflectionBased.ReflectionExtensions.CreateInstanceFromString(Type
type, String propertyValue, Stack`1 recursionDefender) in c:\BuildAgent
\work\636e974733804e57\src\core\OpenRasta\TypeSystem\ReflectionBased
\ReflectionExtensions.cs:line 470
at
OpenRasta.Codecs.AbstractApplicationXWwwFormUrlencodedCodec.ConvertValuesByString(String
strings, Type entityType) in c:\BuildAgent\work\636e974733804e57\src
\core\OpenRasta\Codecs\application\x-www-form-urlencoded
\AbstractApplicationXWwwFormUrlencodedCodec.cs:line 153
at
OpenRasta.TypeSystem.ReflectionBased.ReflectionExtensions.CreateInstanceFrom[T]
(Type type, IEnumerable`1 propertyValues, ValueConverter`1 converter)
in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta\TypeSystem
\ReflectionBased\ReflectionExtensions.cs:line 143
at
OpenRasta.TypeSystem.ReflectionBased.ReflectionBasedType.TryCreateInstance[T]
(IEnumerable`1 values, ValueConverter`1 converter, Object& result) in
c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta\TypeSystem
\ReflectionBased\ReflectionBasedType.cs:line 82
at OpenRasta.TypeSystem.PropertyBuilder.TrySetValue[T]
(IEnumerable`1 values, ValueConverter`1 converter) in c:\BuildAgent
\work\636e974733804e57\src\core\OpenRasta\TypeSystem
\PropertyBuilder.cs:line 88
at OpenRasta.Binding.KeyedValuesBinder.SetPropertyValue[TValue]
(String key, String property, IEnumerable`1 values, ValueConverter`1
converter) in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta
\Binding\KeyedValuesBinder.cs:line 98
at OpenRasta.Binding.KeyedValuesBinder.SetProperty[TValue](String
key, IEnumerable`1 values, ValueConverter`1 converter) in c:\BuildAgent
\work\636e974733804e57\src\core\OpenRasta\Binding
\KeyedValuesBinder.cs:line 80
at OpenRasta.Binding.KeyedValues`1.SetProperty(IObjectBinder
binder) in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta
\Binding\KeyedValues`1.cs:line 37
at
OpenRasta.Codecs.CodecExtensions.<>c__DisplayClass8.<TryAssignKeyValues>b__7(KeyedValues
kv) in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta\Codecs
\CodecExtensions.cs:line 38
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at
OpenRasta.Collections.ObservableIterator`1.<GetEnumerator>d__0.MoveNext()
in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta\Collections
\ObservableIterator.cs:line 42
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
at OpenRasta.Codecs.CodecExtensions.TryAssignKeyValues(ICodec
codec, IHttpEntity entity, IObjectBinder binder, Action`1 assigned,
Action`1 failed) in c:\BuildAgent\work\636e974733804e57\src\core
\OpenRasta\Codecs\CodecExtensions.cs:line 36
at
OpenRasta.Codecs.CodecExtensions.<>c__DisplayClassb.<TryAssignKeyValues>b__a(Boolean
result, IObjectBinder binder) in c:\BuildAgent\work
\636e974733804e57\src\core\OpenRasta\Codecs\CodecExtensions.cs:line 52
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate]
(IEnumerable`1 source, TAccumulate seed, Func`3 func)
at OpenRasta.Codecs.CodecExtensions.TryAssignKeyValues(ICodec
codec, IHttpEntity entity, IEnumerable`1 binders, Action`1 assigned,
Action`1 failed) in c:\BuildAgent\work\636e974733804e57\src\core
\OpenRasta\Codecs\CodecExtensions.cs:line 52
at
OpenRasta.OperationModel.Hydrators.RequestEntityReaderHydrator.TryAssignKeyedValues(IHttpEntity
requestEntity, ICodec codec, Type codecType, IOperation operation) in
c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta\OperationModel
\Hydrators\RequestEntityReaderHydrator.cs:line 88
at
OpenRasta.OperationModel.Hydrators.RequestEntityReaderHydrator.<Process>d__8.MoveNext()
in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta
\OperationModel\Hydrators\RequestEntityReaderHydrator.cs:line 53
at System.Collections.Generic.List`1..ctor(IEnumerable`1
collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at
OpenRasta.Pipeline.Contributors.AbstractOperationProcessing`2.ProcessOperations(ICommunicationContext
context) in c:\BuildAgent\work\636e974733804e57\src\core\OpenRasta
\Pipeline\Contributors\AbstractOperationProcessing.cs:line 24
at
OpenRasta.Pipeline.PipelineRunner.ExecuteContributor(ICommunicationContext
context, ContributorCall call) in c:\BuildAgent\work
\636e974733804e57\src\core\OpenRasta\Pipeline\PipelineRunner.cs:line
187
[2] Tried a ValidationOperationInterceptor class that inherits from
OperationInterceptor and overrides BeforeExecute(IOperation), but the
exception happens before the call to BeforeExecute happens. Tried also
hooking an IPipelineContributor, if I do it After<IRequestDecoding>
(like the OP was doing) obviously it happens the same as when I tried
with an OperationInterceptor, but if I do it Before<IRequestDecoding>
I cannot do a pre-binding to figure out if the binding worked, because
context.PipelineData.Operations.First().Inputs.First().Binder.BuildObject()
always returns a non-successful result, even in the cases where this
exception doesn't happen.
On Jan 10, 5:45 am, Sebastien Lambla <
s...@serialseb.com> wrote:
> Ah, yes, if there's an error you may well find that the pipeline is in rendernow mode, as all contributors before OperationResultInvocation are ignored.
>
> At this stage it's probably easier to hook your contrib after result invocation and before response codec selection, that way you still have a chance to update the OperationResult with your custom type.
>
> We should make codec error handling a bit better in future versions :)
>
>
>
>
>
>
>
> -----Original Message-----
> From:
open...@googlegroups.com [mailto:
open...@googlegroups.com] On Behalf Of Rob
> Sent: 10 January 2011 05:13
> To: OpenRasta
> Subject: [openrasta] Re: How to catch exceptions from codec and pass message out via OperationResult.
>
> Wow fast answer thanks.
> I think I follow what your saying and it makes sense so far.
>
> I have created the following which I believe follows your advice.
> I am still quite new to this aspect so forgive me if i have just plain missed the point.
>
> In Configuration.
> ResourceSpace.Uses.PipelineContributor<OperationDecodingValidator>();
>
> public class OperationDecodingValidator : IPipelineContributor { public void Initialize(IPipeline pipelineRunner) {
>
> pipelineRunner.Notify(CheckRequestDecoding).After<KnownStages.IRequestDecod ing>();