Comments (2)
Some quickly scribbled notes, based on recent conversations:
- Use failure
- Always return
Fail
implementations - Default policy for most APIs: just return
failure::Error
- In cases where consumers of an error are likely to need the extra structured data, return the more specific error type
- Whenever a higher abstraction layer consumes a lower abstraction layer's errors, use
with_context
- Have a top-level trait for "is going to be seen by the human" errors, and require Notion errors to define a conversion to that
- A few different ways we can report information at the top level:
- one-liner default error message
- verbose details
- possibly a log generated even by default?
- Notion error trait (extends Fail) should also include a method for returning the exit code, to keep them organized
from volta.
Rough plan
Fail subtrait for Notion failures
All Notion failures should implement an extended version of the Fail
trait.
The NotionFail
trait has an is_user_friendly()
method for determining whether a type's error messages are fit for end-user consumption, and an exit_code()
method for determining what exit code the error should produce. (The latter might need to evolve later to accommodate signals, depending on how we do #36 and #37.)
trait NotionFail: Fail {
fn is_user_friendly(&self) -> bool;
fn exit_code(&self) -> i32;
}
Make all Notion error types coercible to NotionError
To allow the distributed creation of Notion error types that can all be intermixed via ?
, define an Into
coercion from NotionFail
types to NotionError
.
impl<T: NotionFail> Into<NotionError> for T { ... }
Explicit conversion method for turning external Fails into NotionError
An extension method .unknown()
makes it easy to explicitly mark an error as an "unknown error," i.e. a non-user-friendly error.
trait FailExt {
fn unknown(self) -> NotionError;
}
#[derive(Fail)]
#[fail(...)]
struct UnknownNotionError { ... }
impl NotionFail for UnknownNotionError {
fn is_user_friendly() -> bool { false }
fn exit_code() -> i32 { 1 }
}
impl<T: Fail> FailExt for T {
fn unknown(self) -> NotionError {
UnknownNotionError { ... }.into()
}
}
Mark Context as a NotionFail
In order for with_context
to work with the Notion error types, it should implement NotionFail
whenever its inner error does.
impl<D: NotionFail> NotionFail for failure::Context<D> { ... }
Usage patterns
- functions return
Result<T, NotionError>
by default, except in rare cases when we need more specific error types - any Notion errors interop freely with
NotionError
via?
- non-Notion errors get converted to Notion errors either via:
with_context
to create a user-friendly errore.unknown()
which marks an error as non-user-friendly
from volta.
Related Issues (20)
- Internal Error: EPERM: operation not permitted, open '...\.yarn\cache\.gitignore' HOT 2
- Can I change corepack's platform runtime version after Node.js installation?
- Issue with getting volta to work HOT 4
- `volta run` affects only 1st command in case of chained commands (e.g. when using `&&` operator) HOT 1
- Docs: explicitly mention that omitting `npm` version means using version bundled with Node? (PR#957) HOT 1
- Statement on how to install packages on machines without internet connection?
- How to persist yarn version to `classic` HOT 2
- [Important feature] Implement single command install with nix / home-manager. Add nix flake
- Uninstalling specific versions of node and package manager should be supported HOT 1
- `volta list all` not work if one directory(eg. `pnpm`) not exists HOT 2
- Volta update error: Could not create directory D:\Volta but not D:
- Installing package's man pages globally HOT 5
- Generate Volta man pages
- Running Node with Volta with TMP options HOT 5
- 关于文件路径问题 (Specify installation path)
- Volta/Nuxt problems between multiple user accounts? HOT 2
- SUGGESTION: Move volta config to .voltarc or somewhere else. HOT 1
- I am install [email protected] ,but platform runtime at [email protected],why HOT 1
- volta install cocoapods HOT 2
- Unable to install TypeScript: Could not create shared environment for package 'typescript' 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 volta.