Comments (4)
The value
has an invalid type. So it's not an error that should be catchable IMO, because it's a bug in your application. Same as:
$ node
> JSON.stringify(BigInt(123))
TypeError: Do not know how to serialize a BigInt
This level
behavior is not entirely by design, just a result of encoding happening synchronously, but I can't say it's a bad behavior. Once we fully move to a promise-based implementation (rather than using callbacks internally, where only the asynchronous steps are "captured" by the promise, and synchronous steps instead raise uncaught exceptions) every error would be catched like you desire. But in my personal opinion it's one of the major downsides of Promises.
from level.
Hey, thanks for your response.
I believe it's should be always up to the application developer (no the library developer) to decide, which exceptions should be considered as "fatal" and which exceptions should stop the application immediately.
Our application ("smart contracts execution node") evaluates states of the smart contracts (which are stored and loaded from the Arweave blockchain). Each smart contract is a javascript or wasm code.
If it is a javascript code, it is being run inside https://github.com/laverdet/isolated-vm (because we can't obviously trust external code and we need to have the ability to sandbox the smart contract execution environment).
This works really nice, but after evaluating the state - we're storing it in the node's cache - which is using the level
library.
If the state storing operation fails - I want to simply move to the next contract (and maybe mark the given contract as blacklisted) - but I really don't want the whole application to stop (or at least to be thrown away from the "main" application loop).
So if I'm wrapping the "put" operation in a try-catch - that's my design choice - and I expect to catch all errors that may be thrown during put
(and then - depending on the type of the error - decide what to do next).
Different behaviour is unexpected in this case - and - at least in our case - really "destructive".
I believe that the issue with handling the exception should be noted in the docs...
Is there any timeline to moving to a fully promise-based implementation?
from level.
Is there any timeline to moving to a fully promise-based implementation?
None at this time.
There might be something more specific going on here. I haven't tested it, but a workaround could be explicitly opening the db before you use it:
await db.open()
await db.put(..)
This ensures the put operation isn't deferred until the db has opened itself, which means the operation (including encoding of the value) will happen inside your try/catch
.
from level.
This ensures the put operation isn't deferred until the db has opened itself, which means the operation (including encoding of the value) will happen inside your
try/catch
.
Thanks! This workaround fixes my issue. Appreciate your time and help!
from level.
Related Issues (20)
- Find specific key createReadStream HOT 6
- docker node alpine image exited with code 139 (arm32v7) HOT 4
- Can this be used to polyfill IndexedDB on Node? HOT 3
- [Question] how can "level-js" make data persistence? HOT 2
- db.isOperational is not a function HOT 2
- Trying to store different types of data but getting stored as string HOT 1
- Error while creating a web bundle with esbuild HOT 1
- Recommended way of retrieving a list of all keys? HOT 1
- Live streaming values from a level HOT 6
- Types do not export `destroy` property HOT 1
- Random "Error: Database is not open" errors HOT 14
- Minor Compactions is triggered frequently
- Every time my node script restarts, it creates a new .LDB file in the database directory HOT 1
- Checking if a key exists HOT 1
- Get read access to locked database HOT 1
- how to get all sublevel db HOT 2
- No native build was found error on MacOS with M1 processor HOT 3
- ESM support HOT 4
- Сorrect way to read keys and values HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from level.