public static Config.Parser <From, B> flatMapTry <From, A, B>( this Config.Parser <From, A> aParser, Func <ConfigPath, A, B> f ) => (path, o) => aParser(path, o).flatMapRight(a => { try { return(new Either <ConfigLookupError, B>(f(path, a))); } catch (ConfigFetchException e) { return(new Either <ConfigLookupError, B>(e.error)); } catch (Exception e) { return(new Either <ConfigLookupError, B>(ConfigLookupError.fromException(e))); } });
public static ConfigLookupError parseErrorFor <A>( ConfigPath path, object node, string extraInfo = null ) => ConfigLookupError.wrongType(ImmutableArray.Create( KV.a("path", path.pathStrWithBase), KV.a("expected-type", typeof(A).FullName), KV.a("actual-type", node.GetType().FullName), KV.a("extraInfo", extraInfo ?? ""), KV.a("node-contents", node.asDebugString()) ));
public ConfigFetchException(ConfigLookupError error) : base(error.ToString()) { this.error = error; }
/// Parser that always fails and returns constant. public static Parser <object, A> constantErrorParser <A>(ConfigLookupError error) => (path, _) => Either <ConfigLookupError, A> .Left(error);