GithubHelp home page GithubHelp logo

zalando / faux-pas Goto Github PK

View Code? Open in Web Editor NEW
128.0 128.0 12.0 604 KB

A library that simplifies error handling for Functional Programming in Java

License: MIT License

Shell 1.46% Java 98.54%
completable-future error-handling exception-handling functional-programming java monitoring

faux-pas's People

Contributors

alexanderyastrebov avatar bocytko avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dingxiangfei2009 avatar fatroom avatar gpradeepkrishna avatar mikaojk avatar semernitskaya avatar whiskeysierra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faux-pas's Issues

Add support for CompletableFuture.exceptionally(Function<Throwable, T>)

Using this method to handle only specific exceptions requires to rethrow the original exception in a somewhat weird pattern:

throw e instanceof CompletionException ? (CompletionException) e : new CompletionException(e);

In addition, as usual, the functional interfaces from the JDK only allow to throw unchecked exceptions. Both issues could be supported by some utility higher-order function.

nested throwingFunction() doesn't work on AdoptOpenJDK

This is likely a bug in the OpenJDK, but I wanted to report it first here to see if you could give me a more definitive direction to investigate further, as well as indicate a workaround.

I'm using org.zalando.faux-pas.0.8.0 with OpenJDK 11 on Windows 10:

openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)

I have a section of code that looks like this. Note that it has nested FauxPas throwingFunction(), although I don't know if the nesting has anything to do with it.

//look for a per-page navigation definition file in the form `.filename.ext.navigation.*`
final Optional<Stream<NavigationItem>> pageNavigationDefinition = pageFilename.flatMap(throwingFunction(filename -> {
  final Set<String> navigationFilenames = SUPPORTED_NAVIGATION_FILE_EXTENSIONS.stream()
      .map(ext -> addExtension(DOTFILE_PREFIX + filename + navigationBaseName, ext)).collect(toCollection(LinkedHashSet::new));
  return findAncestorFileByName(sourceDirectory, navigationFilenames, Files::isRegularFile, sourceDirectory)
      .map(throwingFunction(file -> loadNavigationFile(context, contextArtifact, file)));
}));

That compiles just fine on Eclipse 2019-12 (4.14.0). But on AdoptOpenJDK I get this:

unreported exception java.io.IOException; must be caught or declared to be thrown

This error refers to the following line from the code above, because loadNavigationFile() throws an IOException.

.map(throwingFunction(file -> loadNavigationFile(context, contextArtifact, file)));

This same problem occurs in another location, inside a throwingFunction() that is wrapped in a throwingSupplier().

Should this code be allowed? Which is correct here: the Eclipse compiler or the OpenJDK compiler?

And do you know of a workaround, apart from splitting the code sections out and making the stream logic harder to read?

Add overloaded version of partially

public static <T extends Throwable, R> Function<Throwable, R> partially(final Class<T> type, final ThrowingFunction<T, R, Throwable> function) {
    return partially(e -> {
        if (type.isInstance(e)) {
            return function.apply(type.cast(e));
        }
        throw e;
    });
}

This project seems to be heavily-inspired by throwing-function and doesn't comply with the license

This project seems to be heavily-inspired by throwing-function and doesn't comply with the original license.

throwing-function was released/published in February 2016, half a year before the first release of faux-pas

Description

faux-pas:

image

throwing-function:

image

This project seems to be heavily-inspired by throwing-function and doesn't comply with the license

Expected Behavior

The faux-pas project should be compliant with the license and not be a faux pas.

Actual Behavior

The faux-pas project is not compliant with the license and is a faux pas.

Possible Fix

I can think of at least two solutions:

Consider adding support for more functional interface types

List of candidates from java.util.function

  • BinaryOperator
  • BooleanSupplier
  • DoubleBinaryOperator
  • DoubleConsumer
  • DoubleFunction
  • DoublePredicate
  • DoubleSupplier
  • DoubleToIntFunction
  • DoubleToLongFunction
  • DoubleUnaryOperator
  • IntBinaryOperator
  • IntConsumer
  • IntFunction
  • IntPredicate
  • IntSupplier
  • IntToDoubleFunction
  • IntToLongFunction
  • IntUnaryOperator
  • LongBinaryOperator
  • LongConsumer
  • LongFunction
  • LongPredicate
  • LongSupplier
  • LongToDoubleFunction
  • LongToIntFunction
  • LongUnaryOperator
  • ObjDoubleConsumer
  • ObjIntConsumer
  • ObjLongConsumer
  • ToDoubleBiFunction
  • ToDoubleFunction
  • ToIntBiFunction
  • ToIntFunction
  • ToLongBiFunction
  • ToLongFunction
  • UnaryOperator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.