ronomon / deduplication

Fast multi-threaded content-dependent chunking deduplication for Buffers in C++ with a reference implementation in Javascript. Ships with extensive tests, a fuzz test and a benchmark.
MIT License
72 stars 9 forks source link

Why `error` in callback when the library throws exceptions? #2

Closed nlfiedler closed 5 years ago

nlfiedler commented 5 years ago

So the callback is given an error argument, but it is never set. Instead, the library throws exceptions. Why is that the case? And thank you for writing this useful library.

jorangreef commented 5 years ago

Thanks for the question @nlfiedler,

The error argument can be set in the event of an asynchronous operating error, for example see the Execute method in DeduplicationWorker in binding.cc.

Exceptions are thrown in the event of programmer error, for example when arguments have the wrong type or when any part of the interface contract is broken by the user.

Exceptions indicate a programming bug.

Callback errors indicate an operational error.

nlfiedler commented 5 years ago

I see, thanks, I didn't realize that when I was looking at the code.