Beispiel #1
0
 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))); }
 });
Beispiel #2
0
 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())
                                 ));
Beispiel #3
0
 public ConfigFetchException(ConfigLookupError error) : base(error.ToString())
 {
     this.error = error;
 }
Beispiel #4
0
 /// Parser that always fails and returns constant.
 public static Parser <object, A> constantErrorParser <A>(ConfigLookupError error) =>
 (path, _) => Either <ConfigLookupError, A> .Left(error);