Skip to content

Commit 6ce3c0b

Browse files
committed
error styled
1 parent 04330ba commit 6ce3c0b

File tree

2 files changed

+6
-91
lines changed

2 files changed

+6
-91
lines changed

README.zh-CN.md

+5-21
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,14 @@ brew install snm
7070

7171
| 配置项 | 默认值 | 功能描述 |
7272
| ----------------------------- | --------------------------------- | ------------------------------- |
73-
| SNM_STRICT | false | 严格模式开关 |
7473
| SNM_NODE_BIN_DIR | node_bin | node 的二进制存储目录 |
7574
| SNM_DOWNLOAD_DIR | downloads | 文件的下载目录 |
7675
| SNM_NODE_MODULES_DIR | node_modules | npm 、pnpm、yarn 的模块存储目录 |
7776
| SNM_NODE_DIST_URL | https://nodejs.org/dist | nodejs 元数据的获取地址 |
7877
| SNM_DOWNLOAD_TIMEOUT_SECS | 60 | 下载超时时间 ( 单位为 `` ) |
7978
| SNM_NODE_GITHUB_RESOURCE_HOST | https://raw.githubusercontent.com | GITHUB_RESOURCE 地址 |
8079
| SNM_NODE_INSTALL_STRATEGY | auto | node 的安装策略 |
81-
82-
### SNM_STRICT
83-
84-
#### 我们一般建议在 CI 环境中打包严格模式,当你配置为 true 时,你需要遵守以下约定
85-
86-
- 关于 Node
87-
- 你执行命令的目录中必须包含 `.node-version` 文件并正确指定版本
88-
- 关于 packageManager
89-
- 你执行命令的目录中必须包含 `package.json` 文件且正确配置 `packageManager` 字段。
90-
- 在你单条命令的所有生命周期内,只要牵扯到使用包管理器执行 `install``run` 命令,则必须保证使用相同的包管理器。
91-
92-
#### 我们一般建议在本地环境关闭严格模式,当你配置为 false 时你需要注意以下问题
93-
94-
- 关于 Node
95-
- 如果存在 `.node-version` , 那么将遵循你配置的版本去执行。
96-
- 如果不存在 `.node-version` , 那么将使用默认的 node 执行 , 你应该使用 `snm node default <version>` 指定一个默认版本
97-
- 关于 packageManager
98-
- 如果 `package.json` 中存在 `packageManager` 配置 , 那么将遵循你配置的包管理器去执行,如果你使用的命令不符合,将会抛出错误。
99-
- 如果不存在 `package.json` 文件或 `package.json` 中不存在 `packageManager` 配置,那么将使用默认的包管理器执行。
80+
| SNM_NODE_WHITE_LIST | "" | node 白名单版本 |
10081

10182
### SNM_NODE_BIN_DIR
10283

@@ -129,5 +110,8 @@ snm 获取 node 最新版本信息的地址 , 并且我们的下载前缀也会
129110
node 的安装策略,可选值范围如下:
130111

131112
- ask ( 询问用户是否需要安装,这也是默认值 )
132-
- panic ( 如果本地不存在该版本则直接报错 )
133113
- auto ( 静默安装 )
114+
115+
### SNM_NODE_WHITE_LIST
116+
117+
可执行的 node 白名单列表

crates/snm_utils/src/snm_error.rs

+1-70
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ pub enum SnmError {
2828
#[error("Not found: {0}")]
2929
NotFoundResourceError(String),
3030

31-
#[error("Not found package.json {0}")]
32-
NotFoundPackageJsonError(PathBuf),
33-
3431
#[error("Package manager version not match, expected: {expected}, actual: {actual}")]
3532
NotMatchPackageManagerError {
3633
raw_command: String,
@@ -62,18 +59,12 @@ pub enum SnmError {
6259
#[error("Parse package manager error , raw is {0}")]
6360
ParsePackageManagerError(String),
6461

65-
#[error("Unsupported command: {raw_command}")]
66-
UnsupportedCommandError { raw_command: String },
67-
6862
#[error("Duplicate lock file error")]
6963
DuplicateLockFileError { lock_file_vec: Vec<String> },
7064

7165
#[error("{stderr}")]
7266
SNMBinaryProxyFail { stderr: String },
7367

74-
#[error("Cannot find command: {command}")]
75-
CannotFindDefaultCommand { command: String },
76-
7768
#[error("Shasum error: {file_path} , expect: {expect} , actual: {actual}")]
7869
ShasumError {
7970
file_path: String,
@@ -87,55 +78,6 @@ pub enum SnmError {
8778

8879
pub fn friendly_error_message(error: SnmError) {
8980
match error {
90-
SnmError::BuildConfigError(_) => {
91-
eprintln!(
92-
r##"
93-
👹 Build snm config error
94-
95-
The following is a list of configurations supported by snm:
96-
97-
SNM_STRICT:
98-
99-
Whether to enable strict mode, default is false.
100-
In strict mode,
101-
Must be a .node-version file in current_dir and the correct version number configured.
102-
Must be a package.json in current_dir with the correct configuration of packageManager, for example: [email protected]
103-
104-
SNM_NODE_BIN_DIR:
105-
106-
The directory where the node binary is stored, default is node_bin.
107-
108-
SNM_DOWNLOAD_DIR:
109-
110-
The directory where the downloaded file is stored, default is downloads.
111-
112-
SNM_NODE_MODULES_DIR:
113-
114-
The directory where the node_modules is stored, default is node_modules.
115-
116-
SNM_NODE_DIST_URL:
117-
118-
The download address of the node binary, the default is https://nodejs.org/dist .
119-
120-
SNM_GITHUB_RESOURCE_HOST:
121-
122-
The download address of the node binary, the default is https://raw.githubusercontent.com .
123-
124-
SNM_NODE_INSTALL_STRATEGY:
125-
126-
The installation strategy of the node binary, the default is auto. You can choose ask, panic, auto.
127-
128-
SNM_DOWNLOAD_TIMEOUT_SECS:
129-
130-
The download timeout time, the default is 60s.
131-
132-
SNM_PACKAGE_MANAGER_INSTALL_STRATEGY:
133-
134-
The installation strategy of the package manager, the default is auto. You can choose ask, panic, auto.
135-
136-
"##
137-
);
138-
}
13981
SnmError::ParsePackageManagerError(raw) => {
14082
eprintln!(
14183
r##"
@@ -223,16 +165,6 @@ pub fn friendly_error_message(error: SnmError) {
223165
actual.red()
224166
);
225167
}
226-
SnmError::UnsupportedCommandError { raw_command } => {
227-
eprintln!(
228-
r##"
229-
👹 You exec command is unsupported
230-
231-
{}
232-
"##,
233-
raw_command
234-
);
235-
}
236168
SnmError::DuplicateLockFileError { lock_file_vec } => {
237169
eprintln!(
238170
r##"
@@ -289,14 +221,13 @@ pub fn friendly_error_message(error: SnmError) {
289221
);
290222
}
291223
SnmError::HttpStatusCodeUnOk
292-
| SnmError::NotFoundPackageJsonError(_)
293224
| SnmError::GetWorkspaceError
294225
| SnmError::DeserializeError(_)
295226
| SnmError::NetworkError(_)
296227
| SnmError::DialoguerError(_)
297228
| SnmError::VarError(_)
298-
| SnmError::CannotFindDefaultCommand { command: _ }
299229
| SnmError::ZipError(_)
230+
| SnmError::BuildConfigError(_)
300231
| SnmError::IOError(_) => {
301232
let msg = format!("{}", error.to_string());
302233
// panic!("{msg}");

0 commit comments

Comments
 (0)